Hi All,
i am trying to send an one email after the playbook is done, but some how i
am getting the errors, i have tow tasks, and the out put of that tasks i
defined as two set_facts, but some reason it is not working if i use the
two set-facts, if i use only one set_fact it is working fine, below is my
playbook, can some one please help me?
---
- hosts: all
become: true
tasks:
- name: "Printing the Date on the servers as wsadmin user"
become_user: wsadmin
shell: "date"
register: current_date
when: (inventory_hostname in groups ['wsadmindate'])
- name: "Printing the Date on the servers as mqm user"
become_user: mqm
shell: "date"
register: current_date_mqm
when: (inventory_hostname in groups ['mqmdate'])
- set_fact:
cur_date: "{{ current_date.stdout[0:]}}"
# cur_datemqm: "{{ current_date_mqm.stdout[0:]}}"
run_once: True
with_items: (inventory_hostname in groups ['wsadmindate'])
- name: "Displaying the Current Date on the TT servers"
debug:
msg: "Current Date on TT servers is: {{ cur_date}}"
- set_fact:
cur_datemqm: "{{ current_date_mqm.stdout}}"
with_items: (inventory_hostname in groups ['mqmdate'])
- name: "Displaying the Current Date on the TT servers"
debug:
msg: "Current Date on TT servers is: {{ cur_datemqm}}"
- name: "Email The Results"
mail:
to: [email protected]
subject: "TT Email from Ansible With Server Date"
body: |
{% for host in groups ['wsadmindate'] %}
Server {{ host }} Current Date is: {{
hostvars[host]['cur_date'] }}
{% endfor %}
from: deploy
delegate_to: localhost
run_once: True
- name: "Email The Results As MQM user"
mail:
to: [email protected]
subject: "TT Email from Ansible With Server Date"
body: |
{% for host in play_hosts %}
Server {{ host }} Current Date is: {{
hostvars[host]['cur_datemqm'] }}
{% endfor %}
from: deploy
delegate_to: localhost
run_once: True
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/2344bcce-e6f3-4215-946c-edc478f6d83a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.