Ansible and Jenkins Continuous Integration

ansible_badge

This post will assume you have the following already installed and configured:

  1. Ansible Tower
  2. Jenkins

Steps for proper integration through the Tower CLI:

  1. Install Tower CLI on your Jenkins server – https://github.com/ansible/tower-cli
  2. Create Tower CLI config file (i.e. ~/.tower_cli.cfg)
  3. Copy .tower_cli.cfg to your Jenkins user home directory <— this is the magic key

At this point you should be able to kick off Ansible Tower jobs from the command line within your Jenkins server using the Jenkins user.

Next, all you need to do add a “Execute shell’ build step with the following:

/usr/bin/tower-cli job launch --job-template=XX

* Where XX is the ID of the Job Template you wish to run.

If you need to pass in arguments to your Ansible Playbooks, this can be achieved by creating a temporary file. Use the following as an example:

rm -f $WORKSPACE/ansible-deploy.json
echo "{ \"branch_name\": \"develop\", \"env\": \"dev\", \"host_filter\": \"app*-d\" }" > $WORKSPACE/ansible-deploy.json
/usr/bin/tower-cli job launch --job-template=XX --extra-vars $WORKSPACE/ansible-deploy.json

* Where XX is the ID of the Job Template you wish to run.

And that’s it! Enjoy your new CI deployment mechanism within Jenkins.

Posted in Ansible, Jenkins Tagged with: , ,

Ansible Python 2.7.7 Playbook

ansible_badge

After much testing, here is a cool playbook that does an altinstall of Python 2.7.7:

---
 -
 hosts: "{{ host_filter }}"
 sudo: true
 tasks:
 -
 name: "install the 'Development tools' package group"
 yum: "name=\"@Development tools\" state=present"
 -
 name: "register output of python2.7"
 raw: "python2.7 --version | awk '{print $2}';"
 register: pyver
 failed_when: " pyver.stdout == 'Python 2.7.7'"
 -
 name: "python source"
 copy: "src=files/Python-2.7.7.tgz dest=/usr/local/src/"
 -
 name: "ez_setup.py script"
 copy: "src=files/ez_setup.py dest=/usr/local/src/"
 -
 name: "extract python"
 command: "chdir=/usr/local/src/ creates=/usr/local/src/Python-2.7.7 tar zxvf Python-2.7.7.tgz"
 -
 name: "source install configure"
 command: "chdir=/usr/local/src/Python-2.7.7 ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS=\"-Wl,-rpath /usr/local/lib\""
 -
 name: "source install make"
 command: "chdir=/usr/local/src/Python-2.7.7 make"
 -
 name: "source install make altinstall"
 command: "chdir=/usr/local/src/Python-2.7.7 make altinstall"
 -
 name: "install ez_setup"
 command: "python2.7 /usr/local/src/ez_setup.py"
 -
 name: "install pip"
 command: "easy_install-2.7 pip"
 -
 name: "install virtualenv2.7"
 pip: "name=virtualenv executable=pip2.7"
 -
 name: "setup extra python stuff"
 pip: "name=virtualenvwrapper"
Posted in Ansible, Python Tagged with: , ,