From f0aaf767ec96d5cd19b5513248de3bf92758b59c Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Tue, 31 Jan 2017 11:53:38 +0100 Subject: [PATCH] Conventions: add "check mode" section --- CONVENTIONS.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index cb8f0e8..048f76a 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -182,6 +182,29 @@ copy: The source file or template shouldn't to be prefixed for ordering (eg. `z-` or `zzz-`). It's the task's responsibility to choose how destination files must be ordered. +### check mode + +Ansible can run playbooks in "check mode" with the `--check` argument of `ansible-playbook`. It won't do any changing action but will report what would be changed or not. + +When an action depends on a variable registered by a previous action (that performs no change, like a grep, stat…) we should add a `always_run: yes` to the action. In Ansible 2.2, the behaviour has been replace by `check_mode: yes.` Exemple : + +``` +- name: Check if Munin plugins exists + stat: + path: /etc/munin/plugins/ + register: munin_plugins_dir + #check_mode: no (for migration to Ansible 2.2) + always_run: yes + +- name: Get Munin plugin + copy: + src: munin/drbd-plugin + dest: /etc/munin/plugins/drbd + mode: "755" + when: munin_plugins_dir.stat.exists + notify: restart munin-node +``` + ### packages installation When making a role or a task the necessary packages must be installed explicitly.