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:
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:
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