Skip to main content

Posts

Showing posts with the label playbook

Useful ansible stuff

inventory_hostname ‘ inventory_hostname ‘ contains the name of the current node being worked on…. (as in, what it is defined in your hosts file as) so if you want to skip a task for a single node – - name: Restart amavis service: name=amavis state=restarted when: inventory_hostname != "boris" (Don’t restart Amavis for boris,  do for all others). You could also use : ... when: inventory_hostname not in groups['group_name'] ... if your aim was to (perhaps skip) a task for some nodes in the specified group.   Need to check whether you need to reboot for a kernel update? If /vmlinuz doesn’t resolve to the same kernel as we’re running Reboot Wait 45 seconds before carrying on… - name: Check for reboot hint. shell: if [ $(readlink -f /vmlinuz) != /boot/vmlinuz-$(uname -r) ]; then echo 'reboot'; else echo 'no'; fi ignore_errors: true register: reboot_hint - name: Rebooting ... command: shutdown -r now "Ansible kernel update applied...

Ansible issues

is not a valid attribute for a Play When ever you get the above error firstly crosscheck that the ansible attribute you have mentioned is correct. If it is correct then the issue probably is that you have created tasks as follows: --- - vars_prompt: - name: "var1" prompt: "Please pass variable" private: no - fail: msg="var1 is not passed or blank" when: var1 is undefined or ( var1 is defined and storeid == "" ) when it should be as follows: --- vars_prompt: - name: "var1" prompt: "Please pass variable" private: no tasks: - fail: msg="var1 is not passed or blank" when: var1 is undefined or ( var1 is defined and storeid == "" ) the example referenced is just a task. It is not a valid playbook because it is missings a hosts declaration and the module call is not under a tasks section. ERROR! conflicting action statements: fail, ...