Edgars
(Edgars)
October 22, 2012, 2:48pm
1
I want to send email with task exit status after it is completed:
Here is my playbook:
name: deploy cfg
hosts: all
user: admin
sudo: True
tasks:
name: copy cfg
action: copy src=/var/repo/file.cfg dest=/etc/file.cfg owner=root group=root mode=755
register: status
name: Send status report
hosts: smtprelaysrv
user: admin
sudo: True
tasks:
name: Send status report
action: mail subject=‘Ansible report’ to=admin from=ansible-report@localhost body=‘Ansible task has completed with status ${status.rc}’
However it seems that mail module does not understand variable ${status.rc} nor ${status}.
Am I doing something wrong?
Thanks,
Edgars
Mail module shouldn't even need to care, as templating is generic
Can you describe what behavior you are seeing?
Edgars
(Edgars)
October 22, 2012, 2:52pm
3
I am receiving email with body:
Ansible task has completed with status ${status.rc}
What I want to is:
Edgars
(Edgars)
October 23, 2012, 7:35am
4
No, double-quotes does not work either.
Edgars
(Edgars)
October 23, 2012, 9:20am
6
Yes, it works that way. So it seems that variables are not global in whole playbook!? Say, if I have such playbook structure:
name: Deploy
hosts: all
tasks:
action: command uptime
register: status
name: Send report
hosts: smtp_relay_server
tasks:
action: mail subject=${status}
It does not pass variable from one host block to another?
Perhaps you were trying to access it from a different host record, or
the groups in one did not always contain all of the other.
Edgars
(Edgars)
October 23, 2012, 12:58pm
8
I am not sure if I understood you. Yes, i am trying to access that variable from different host record. Doesn’t it work that way?
I'd suggest stopping by IRC.
Edgars
(Edgars)
October 23, 2012, 3:19pm
10
I am there, asked already twice, but I guess my questions “lost in translation”