Committing the code and publishing

Now that we have our completed role, we need to push it to a public GitHub repository. There are a few reasons why it needs to be published to a public repository, the most important of which is that any potential user will need to download your role. Also, Ansible Galaxy links to the repository, allowing users to review your role before they choose to execute it as part of their playbooks.

On all GitHub pages, when you are logged in, there is a + icon in the top right; clicking this will bring up a menu that contains options for creating a new repository and importing one, as well as gists and organizations. Select New repository from the menu and you will be presented with a screen that looks as follows:

Name the repository and enter a description; it is important that you name your repository ansible-role-your-role-name. The name of the role in Ansible Galaxy will depend on the name you give after ansible-role, so, in the previous example, our role will be called your-role-name and, for the role we are going to be publishing, it will be called docker.

Now that we have our repository, we need to add the files for our role. Go back to the folder that contains your role on the command line and then run the following commands to initialize the Git repository locally. Push it to GitHub, making sure that you replace the repository URL with that of your own repository:

$ git init
$ git add -A .
$ git commit -m "first commit"
$ git remote add origin [email protected]:russmckendrick/ansible-role-docker.git
$ git push -u origin master

You should now have your files uploaded, and your repository should look not too dissimilar to the following:

If you have any problems pushing your code, I would recommend reading through the excellent documentation provided by GitHub on setting up Git (https://help.github.com/articles/set-up-git/) and pushing your first files (https://help.github.com/articles/create-a-repo/).

Now that we have our files uploaded and available, we can sign in to Ansible Galaxy using our GitHub credentials and then import our role. Head to the Ansible Galaxy home page at https://galaxy.ansible.com/ and then click on the Sign in with GitHub link; this will take you to GitHub and ask you to confirm that you are OK with giving Ansible Galaxy permission to access information on your account. Proceed as prompted and you will be returned to Ansible Galaxy.

Clicking on the My Content link in the top menu will take you to a page where you can import content from GitHub; if you do not see your repository listed, click on the refresh icon next to the search box:

When you see your repository listed, click on the on/off switch next to the role and that should do it. Your role is now imported. Clicking your username in the top menu will bring up a drop-down list; from this list, select My Imports. This will give you the logs of your import:

Now your role has been published; you can view your role by clicking on the link at the top, where it says russmckendrick/ansible-role-docker. This will take you to the Ansible Galaxy page for your newly added role, for example, https://galaxy.ansible.com/russmckendrick/docker/:

As you can see, all of the metadata we added is present in the listing along with links to view the README file, which was imported from GitHub, and also links to GitHub itself.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.142.248