Temporarily disabling an ansible task in a playbook

I have a playbook that provisions a vagrant box. Among other things is installs docker:

- name: install docker
  apt:
    name: "docker.io"
    state: latest

For reasons, I wanted this temporarily disabled in repeated runs of the playbook. Enter the when: statement:

- name: install docker
  apt:
    name: "docker.io"
    state: latest
  # Do this for example when you choose docker to be 
  # installed from a vagrant provisioner but do not 
  # want to remove the task from the playbook.
  when: 0 > 1

You can of course switch from the condition of 0 > 1 to a variable that takes the values true or false and even drive this from the command line by setting the value of the variable.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s