Filter specific string from file content and it needs to be looped into mail module

12 views
Skip to first unread message

Pandu jh

unread,
Nov 23, 2018, 7:27:10 AM11/23/18
to Ansible Project
I have multiple files in a path and it contains mail id of the users. 
I need to loop the file content using with_items and filter users ID from the file content.
That ID's should be passed into mail module, mail needs to be sent to those user ID's. 

Please help me filter only ID form the file content and it needs to be looped into mail module.

cat /test/user1

Name: Anton

cat /test/user2
Name: Jeniffer

      - shell:  cat {{ item }}  | egrep -v 'provided|valid'
        register: file_content
        with_items:
          - /test/user1
          - /test/user2

      - name: Send mail notification to the user
        mail:
          host: mailrelay.xxx.com
          port: 25
          subject:  Information
          body: "{{ lookup('file', '{{  req_path  }}/{{ req }}') + lookup('file', '{{ mail_sign  }}') }}"
          from: ad...@xxx.com
          to: jenni...@xxx.com
          charset:  utf8
        run_once: true


Reply all
Reply to author
Forward
0 new messages