Created
May 13, 2020 23:29
-
-
Save luckylittle/d6274a6449e24f5c9be3f6b892d52fc8 to your computer and use it in GitHub Desktop.
Red Hat Ansible Tower - passing vars from one playbook to another in the workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - name: 01 | Run Normal Tasks | |
| hosts: all | |
| gather_facts: no | |
| vars: | |
| ansible_connection: local | |
| tasks: | |
| - debug: var=vars | |
| - name: 01.1 | FACT >> Set Status | |
| set_fact: | |
| _failed_status: 'not_set' | |
| - name: 01.2 | Debug >> FAIL for rhel01 | |
| debug: | |
| msg: "{{ inventory_hostname }}" | |
| failed_when: " 'rhel01' in inventory_hostname " | |
| - name: 01.3 | Debug >> FAIL for rhel02 | |
| debug: | |
| msg: "{{ inventory_hostname }}" | |
| failed_when: " 'rhel02' in inventory_hostname " | |
| - name: 01.4 | Set Flag | |
| set_fact: | |
| _failed_status: 'pass' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - name: 02 | Create in-memory Group | |
| hosts: all | |
| gather_facts: no | |
| tasks: | |
| - debug: | |
| msg: "{{ _failed_status }}" | |
| - name: 02.1 | Create In Memory Group | |
| add_host: | |
| name: "{{ item }}" | |
| group: 'failed_hosts' | |
| when: hostvars[item]._failed_status != 'pass' | |
| loop: "{{ play_hosts }}" | |
| - name: 03 | Send SlackNotify | |
| hosts: failed_hosts | |
| gather_facts: no | |
| vars: | |
| ansible_connection: local | |
| tasks: | |
| - name: 03.1 | DEBUG >> Output all Hosts | |
| debug: | |
| msg: "{{ inventory_hostname }}" | |
| - name: 03.2 | Test Slack | |
| slack: | |
| username: 'AWX' | |
| msg: "Failed Notification for Host {{ inventory_hostname }}" | |
| token: "11111111111111111111111111111111111111111111" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment