Invoke another 'play' based on output of another play - Ansible -
i trying use ansible check if selinux enabled (set enforcing), , if not, enable it. play enable selinux must invoked if selinux disabled.
the playbook looks so:
- hosts: # root should execute this. remote_user: root become: yes tasks: # check if selinux enabled. - name: check if selinux enabled tags: selinuxcheck register: selinuxcheckout command: getenforce - debug: var=selinuxcheckout.stdout_lines - name: enable selinux if not enabled tags: enableselinux selinux: policy=targeted state=enforcing when: selinuxcheckout.stdout_lines == "enforcing" - debug: var=enableselinuxout.stdout_lines when run this, task enableselinux fails reason, "conditional check failed". output is:
task [debug] ******************************************************************* task path: /root/ansible/playbooks/selinuxconfig.yml:24 ok: [localhost] => { "selinuxcheckout.stdout_lines": [ "enforcing" ] } task [enable selinux if not enabled already] *********************************** task path: /root/ansible/playbooks/selinuxconfig.yml:26 skipping: [localhost] => {"changed": false, "skip_reason": "conditional check failed", "skipped": true} my questions:
1. correct way play execute depending on output play?
2. how work?
your playbook correct. stdout_lines list. have compare first element in list. try this:
when: selinuxcheckout.stdout_lines[0] == "enforcing"
Comments
Post a Comment