I started my Ansible series really with the intention of getting to know Git/GitHub a bit better but Ansible was so awesome I couldn’t put it down. Now that I have built a couple of example playbooks its time to “commit” those into GitHub. For starters, we need Git/GitHub installed on our system. In my case I am doing everything from my Ansible server, though you may want to do this on another system. Thanks to yum, the install is pretty easy
yum install git
I had already run this on my Ansible server so I could “pull” the Ansible code. Now I want to setup my username so:
git config --global user.name "yourusername"
Next register your email account for your GitHub account
git config --global user.email "youremail"
Now on to authentication, it’s high time I stop using passwords for everything and setup SSH keys so, lets do that. To create the public key enter:
ssh-keygen -t rsa -C "email@example.com"
- While logged in as root it will save to /root/.ssh/id_rsa)
- Next enter your secure password
- With the key now created, log into GitHub and click on the gear icon (Settings) in the upper right corner
- Click on SSH keys
- Click the add SSH keys button
- Provide a title such as “ansible VM” or whatever used to identify the computer
- Back in your terminal window type
less /root/.ssh/id_rsa.pub
- Copy the contents of the file and paste it into the Key text box
- Click the Add key button
- Back in your terminal window type
ssh -T git@github.com
- Accept the key from github.com
- Enter the pass phrase for your key
- You should now be logged into GitHub with your keys!
- Now, switch the to folder where you are saving your Ansible playbooks
- Type git init
- Type git add .
- Type git commit -m ‘playbooks’
- Find the URL from your Git repository (create one if you haven’t), make sure to click on SSH, not HTTPS and copy that
- Type git remote add origin git@github.com:user/repository.git
- Type git remote -v
- Type git push origin master then enter the pass phrase for your SSH key
Now if I go to my repository, I can see my .yml files checked in!
From now on, as we create or update our playbooks we can check them into GitHub for safe keeping and sharing!