Alister West

home is where your code is ...

Ansible Tips

apt_module

# Speed up dev - run update only once a day
- apt: update_cache=yes cache_valid_time=86400

# Override libncurses-dev always falsely reported as 'changed'
- name: install libncurses-dev
  apt: pkg=libncurses-dev state=latest
  changed_when: false

Register Variables

The command module will usually produce a nasty orange 'changed' output.

When no change was made it would be nice to get green 'OK' message.

So run in 2 steps where step-1 registers if step-2 needs to run.

http://serverfault.com/questions/644082/running-apt-get-autoremove-with-ansible

- name:         Check if anything needs autoremoving
  shell:        apt-get -y --dry-run autoremove | grep -q "0 to remove"
  register:     check_autoremove
  ignore_errors: true
  changed_when: false
  always_run:   true

- name:    Autoremove unused packages
  command: apt-get -y autoremove
  when:    "check_autoremove.rc != 0"

use 'created', 'removed' args

- name: "disable default vhost"
  command: a2dissite 000-default
  args: { removes: "/etc/apache2/sites-enabled/000-default.conf" }
  notify: restart apache
By Alister West