Hi Dick/Abhijit,

The problem is not searching the file in the location. the problem is 
"attach" inside  mail module doesn't recognize the variable reference(it 
takes hard coded path).I dont want to  hard code path inside attach. I want 
to use the variable reference inside attach module.

In the debug of "list_html_files" below it clearly shows that the html 
files are present. i am using ansible.2.7.5 

Pls suggest how can i achieve this.


ok: [10.253.173.111] => {
    "msg": {
        "changed": true, 
        "cmd": "find /tmp/sanity_RIC1/ -type f -regex \".*.html\" | tr -s 
'\\n' ' ' | xargs | sort", 
        "delta": "0:00:00.006235", 
        "end": "2019-09-05 04:03:01.195198", 
        "failed": false, 
        "rc": 0, 
        "start": "2019-09-05 04:03:01.188963", 
        "stderr": "", 
        "stderr_lines": [], 
        "stdout": "/tmp/sanity_RIC1/sanity_RIC1IC01_20190905-040234.html 
/tmp/sanity_RIC1/sanity_RIC1IC02_20190905-040247.html", 
        "stdout_lines": [
            "/tmp/sanity_RIC1/sanity_RIC1IC01_20190905-040234.html 
/tmp/sanity_RIC1/sanity_RIC1IC02_20190905-040247.html"
        ]
    }


On Thursday, September 5, 2019 at 6:03:22 PM UTC+5:30, Abhijeet Kasurde 
wrote:
>
> Additionally, you can use `fileglob` - 
> https://docs.ansible.com/ansible/latest/plugins/lookup/fileglob.html for 
> getting desired files from given directory structure.
>
> On Thu, Sep 5, 2019 at 5:14 PM Dick Visser <[email protected] 
> <javascript:>> wrote:
>
>> On Thu, 5 Sep 2019 at 12:11, Rakesh Parida <[email protected] 
>> <javascript:>> wrote:
>> >
>> > I have a code as below and i have my html files present in /tmp/sanity/ 
>> .
>> > but i am getting error as "Failed to send mail: can't attach file" i 
>> get file not found
>>
>> Well that's pretty clear: the file is not found.
>> Debug what is in list_html_files.stdout_lines[0] and adjust that.
>> Without any further information it's hard to tell.
>>
>> On a related note, instead of fragile shell find/tr/xargs/sort , I
>> would strongly suggest to use the 'find' module.
>> That will at least return a standard data structure (which is easier
>> to offer help with).
>>
>>
>> Dick
>>
>>
>>
>> >  - name: list html files
>> >      run_once: true
>> >      local_action: shell find /tmp/sanity/ -type f -regex ".*.html" | 
>> tr -s '\n' ' ' | xargs | sort
>> >      register: list_html_files
>> >    - debug: msg="{{ list_html_files }}"
>> >
>> >    - name: generate final email body
>> >      run_once: true
>> >      local_action: shell for i in `find /tmp/sanity/ -type f -regex 
>> ".*email.*.txt" | sort`; do cat $i ;done
>> >      register: email_body
>> >    - debug: msg="{{email_body}}"
>> >
>> >    - name: email results
>> >      become: true
>> >      ignore_errors: true
>> >      run_once: true
>> >      mail:
>> >         host: "{{smtp_host}}"
>> >         port: 25
>> >         subject: "raka"
>> >         body: '{{ email_body.stdout }}'
>> >         from: xxxxxxx
>> >         to: "{{ email | default('xxxxxx') }}"
>> >         attach:
>> >            -  '{{ list_html_files.stdout_lines[0] }}'
>> >         charset: utf8
>> >      delegate_to: localhost
>> >
>> > --
>> > 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 [email protected] <javascript:>.
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/69c639e2-ce8f-4931-90f4-bdb3ee0c00b5%40googlegroups.com
>> .
>>
>>
>>
>> -- 
>> Dick Visser
>> Trust & Identity Service Operations Manager
>> GÉANT
>>
>> -- 
>> 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 [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/CAL8fbwP2kZX9OUGm%2BFFY8FyK2D%3D5RpG5y6JkXpkctheUVmPMqg%40mail.gmail.com
>> .
>>
>
>
> -- 
> Thanks,
> Abhijeet Kasurde
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/db3d886d-13c7-439c-a7ef-9a8f623d4937%40googlegroups.com.

Reply via email to