Get to the point, Ansible

As you change your Ansible devops code, the time you spend testing each Ansible run increases.

Did you add a new package, configuration file, or service task to your Ansible code? Launch ansible-playbook and wait while it first runs your 200 other Ansible tasks.

Did Ansible tell you you’ve botched your syntax? Fix it and run ansible-playbook again!

Testing it faster

An obvious approach would be to comment out the code above your changes. That way Ansible skips the old code, and starts from your new code instead. Comment out your site configuration file, and perhaps parts of your Ansible role. Here is an example:


- name: Run common roles
  hosts: all
# comment this out
#    - role: mysite.common
#    - role: galaxy.ntp
    - role: mysite.newthing


# comment this out too
#- include: postgres.yml
#- include_role:
#    name: mysite.oldthing

- name: install packages
      - libssl-dev

Testing it easily

Manually commenting and un-commenting is tedious and error-prone!

Did you know Ansible has a command-line flag to skip ahead? You can skip manually commenting and un-commenting code!

ansible-playbook site.yml --start-at-task 'install packages'

Unique names

Do you already have a task named install packages? Consider adding more description to your task name! However, assuming you can’t rename tasks, you can also include the role name:

ansible-playbook site.yml --start-at-task 'mysite.newthing : install packages'

Don’t quote me

Notice we used single quotes ' and not double quotes ". If you have any punctuation in your task names, such as “Install packages!”, the single quotes are required!

See also: bash documentation on single quotes, vs double quotes .