How to email task's status

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?

I am receiving email with body:

Ansible task has completed with status ${status.rc}

What I want to is:

No, double-quotes does not work either.

It works fine for me:

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.

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.

I am there, asked already twice, but I guess my questions “lost in translation” :slight_smile: