On 8/28/19 9:35 AM, Mohtashim S wrote:
> Sorry for the missing quotes. It was a typo. 
> 
> Thank you for the suggestion however, I'm compelled to use shell module. 
> Using command or script is not an option. 
> 
> My actual playbook looks like this:
> 
> |
>     shell: "ls -ltr {{ BASEPATH }}/{{ vars[item.split('.')[1]] }}/{{ item | 
> basename }} | awk '{$2=$4=$5=""; print $0}'
> | tr '\n' '\t' | tr -s "";"
> |
> 
> 
> It gives error when using command module and I had already discussed on a 
> seperate post where using shell was recommended.

True, but why don't you use the ansible stat module instead?

Regards
        Racke

> 
> 
> 
> 
> 
> On Wednesday, August 28, 2019 at 12:38:17 PM UTC+5:30, Sudheer Satyanaraana 
> wrote:
> 
> 
>     On 28/08/19 12:20 PM, Mohtashim S wrote:
>>     Below is my playbook:
>>
>>     |
>>        -name:"Collecting File details"
>>          shell: "ls -ltr {{ item }} | awk '{$2=$4=$5=""; print $0}' | tr 
>> '\n' '\t' | tr -s "";
>>
>>          with_fileglob:
>>
>>            - "{{playbook_dir }}/tmpfiles/*"
>>     |
>>
>>
>>     I get syntax error due to the awk command as below. 
>>
>>         ERROR! Syntax Error while loading YAML.
>>           did not find expected key
>>              shell:  "ls -ltr {{ item }} | awk '{$2=$4=$5=""; print $0}' | 
>> tr '\n' '\t' | tr -s " ";
>>                                                                              
>>  ^ here
>>         We could be wrong, but this one looks like it might be an issue with
>>         missing quotes. Always quote template expression brackets when they
>>         start a value. For instance:
>>
>>
>>     Can you please suggest how can I incorporate such a awk in ansible shell 
>> module ?
> 
>     There are a few things you should know and consider:
> 
>     From the shell command's documentation: 
> https://docs.ansible.com/ansible/latest/modules/shell_module.html
>     <https://docs.ansible.com/ansible/latest/modules/shell_module.html>
> 
>     "If you want to execute a command securely and predictably, it may be 
> better to use the command
>     
> <https://docs.ansible.com/ansible/latest/modules/command_module.html#command-module>
>  module instead. Best practices
>     when writing playbooks will follow the trend of using command
>     
> <https://docs.ansible.com/ansible/latest/modules/command_module.html#command-module>
>  unless the |shell| module is
>     explicitly required. When running ad-hoc commands, use your best 
> judgement."
> 
>     So, consider using the command module.
> 
>     From the command module's documentation: 
> https://docs.ansible.com/ansible/latest/modules/command_module.html
>     <https://docs.ansible.com/ansible/latest/modules/command_module.html>
> 
>     "The command(s) will not be processed through the shell, so variables 
> like |$HOME| and operations like |"<"|, |">"|,
>     |"|"|, |";"| and |"&"| will not work. Use the shell
>     
> <https://docs.ansible.com/ansible/latest/modules/shell_module.html#shell-module>
>  module if you need these features."
> 
>     The pipe | won't work inline.
> 
>     Also, your YAML has quoting issues. It becomes hard to quote long line 
> commands that has a mix of single and double
>     quotes in YAML. You are better off using the script module.
> 
>     
> https://docs.ansible.com/ansible/latest/modules/script_module.html#script-module
>     
> <https://docs.ansible.com/ansible/latest/modules/script_module.html#script-module>
> 
>     Try the script module and see how it goes.
> 
> 
>     -- 
> 
>     Sudheer Satyanarayana
>     DevOps And Development Consultant
>     AWS Solutions Architect - Associate 
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ae1adf15-ea04-4d2e-81a8-071993969de5%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/ae1adf15-ea04-4d2e-81a8-071993969de5%40googlegroups.com?utm_medium=email&utm_source=footer>.


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

-- 
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/9b04621d-14d6-b06e-39ce-14a7bfa96757%40linuxia.de.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to