HOw to send email withe the Two register variables.

14 views
Skip to first unread message

Raj Martha

unread,
Jun 12, 2019, 2:43:27 PM6/12/19
to Ansible Project
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: kanna.r...@gmail.com
          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: kanna.r...@gmail.com
          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

Stefan Hornburg (Racke)

unread,
Jun 13, 2019, 1:08:23 AM6/13/19
to ansible...@googlegroups.com
On 6/12/19 8:43 PM, Raj Martha wrote:
> 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?
>
>

Can you show the errors please?

Regards
Racke
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To post to this group, send email to ansible...@googlegroups.com <mailto:ansible...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/2344bcce-e6f3-4215-946c-edc478f6d83a%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/2344bcce-e6f3-4215-946c-edc478f6d83a%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Raj Martha

unread,
Jun 13, 2019, 9:46:29 AM6/13/19
to Ansible Project
i am getting the below error,,,

 msg: |-
    The task includes an option with an undefined variable. The error was: 'cur_datemqm' is undefined

    The error appears to have been in '/opt/WebSphere/scripts/Applications/projects/timetravel/printdate.yml': line 23, column 9, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

               msg: "Current Date on TT servers is: {{ cur_date}}"
          - name: "Displaying the Current Date on the TT servers"
            ^ here
Reply all
Reply to author
Forward
0 new messages