I'm writing an Ansible playbook and have a task which will always fail in check mode:
hosts: ... tasks: - set_fact: filename="{{ansible_date_time.iso8601}}" - file: state=touch name={{filename}} - file: state=link src={{filename}} dest=latest
In check mode, the file will not be created so the link
task will always fail. Is there a way to mark such a task to be skipped when running in check mode? Something like:
- file: state=link src={{filename}} dest=latest when: not check_mode
If you assign the never tag to a task or play, Ansible will skip that task or play unless you specifically request it ( --tags never ).
To force a task to run in check mode, even when the playbook is called without --check , set check_mode: yes . To force a task to run in normal mode and make changes to the system, even when the playbook is called with --check , set check_mode: no .
The easiest way to run only one task in Ansible Playbook is using the tags statement parameter of the “ansible-playbook” command. The default behavior is to execute all the tags in your Playbook with --tags all .
The easiest way to do a dry run in Ansible is to use the check mode . This mode works like the --syntax-check command, but on a playbook level.
Ansible 2.1 supports ansible_check_mode
magic variable which is set to True
in check mode (official docs). This means you will be able to do this:
- file: state: link src: '{{ filename }}' dest: latest when: not ansible_check_mode
or
- file: state: link src: '{{ filename }}' dest: latest ignore_errors: '{{ ansible_check_mode }}'
whichever you like more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With