Ansible Packages


In this series of blog posts, I will be talking about Ansible. Ansible is a powerful automation tool that you can learn quickly.

One of the important Ansible Modules that I use in almost every playbook is the package manager module to install and update system packages. This is important for installing dependencies for your application.

You can use this in your playbook by using either the yum or apt modules depending on your target operating system.

http://docs.ansible.com/ansible/yum_module.html

http://docs.ansible.com/ansible/apt_module.html

For single packages its quite easy:

- name: ensure apache is at the latest version
  yum: pkg=httpd state=latest

You can even specify options like latest which will ensure the package is the latest version.

Moving onto bigger things, if you have a whole lot of packages you want installed on the server you can bunch them all up together, for example:

- name: ensure required packages are installed
  action: yum name= state=present
  with_items:
    - libyaml
    - git
    - ntp
    - libselinux-python

Its also possible to use the command to install RPMs and as a bonus it wont mess up your yum database. You can do this by providing the path to the RPM like so:

- name: ensure required packages are installed
  sudo: yes
  action: yum name= state=present disable_gpg_check=yes
  with_items:
    - /tmp/command-tool.rpm
    - /tmp/main-config.rpm
    - /tmp/app-deploy.rpm

As you can see, this is a simple way to have packages on your servers installed and kept up to date. There are many more options on these modules as you will find in the ansible documentation, but these simple examples should get you started.