*ansible_play_hosts_all *is a list, which is what you say that you want, so
all should be fine.

Unless your script does not really expect a list, which I think is what is
happening.
If that is the case, either adopt your script to handle a list.
Or, turn the list into string, separated by spaces:


*{{ ansible_play_hosts_all | join(" ") }}*



On Wed, 21 Jun 2023 at 15:50, Prady A <pradyumna....@gmail.com> wrote:

> Hi all
>
> I am trying to pass the ansible hostnames as an array list to python
> script but could not figure out where the extra characters are coming from.
> I am  passing with ansible_play_hosts_all variable.
> In my host file there are 2 hoosts 1ld501 and 1ld994. but it is passing
> some unexpected character marked in red.
>
> *Playbook:*
> ---
> - name: Execute writetoexcel python
>   script: ./roles/writetoexcel.py *{{ ansible_play_hosts_all }}*
>   args:
>     executable: python3
>   delegate_to: localhost
>
> *Output:*
> <localhost> EXEC /bin/sh -c ' python3
> /root/.ansible/tmp/ansible-tmp-1687354259.71-24015-237464957552077/writetoexcel.py
> [*u'"'"'*1ld501*'"'"'*,* u'"'"*'1ld994*'"'"'*] && sleep 0'
>
> changed: [1ld501 -> localhost] => {
>     "changed": true,
>     "rc": 0,
>     "stderr": "",
>     "stderr_lines": [],
>     "stdout": "[['[u1ld501,', 'u1ld994]']]\nData written to Excel
> successfully!\n",
>     "stdout_lines": [
>         "[['[u1ld501,', 'u1ld994]']]",
>         "Data written to Excel successfully!"
>     ]
> }
>
> Tried with Ansible_hostname no extra characters are there. It is as
> expected. Please suggest.
>
> *Playbook:*
>  ---
> - name: Execute writetoexcel python
>   script: ./roles/writetoexcel.py* {{ ansible_hostname }}*
>   args:
>     executable: python3
>   delegate_to: localhost
>
> *Output:*
> <localhost> EXEC /bin/sh -c ' python3
> /root/.ansible/tmp/ansible-tmp-1687354332.97-25377-185430066289739/writetoexcel.py
> *1ld994* && sleep 0'
> <localhost> EXEC /bin/sh -c 'rm -f -r
> /root/.ansible/tmp/ansible-tmp-1687354332.95-25376-35834468227973/ >
> /dev/null 2>&1 && sleep 0'
> changed: [jp1ld501 -> localhost] => {
>     "changed": true,
>     "rc": 0,
>     "stderr": "",
>     "stderr_lines": [],
>     "stdout": "[['1ld994']]\nData written to Excel successfully!\n",
>     "stdout_lines": [
>         "[['1ld994']]",
>         "Data written to Excel successfully!"
>     ]
> }
>
> Regards
> PD
>
> --
> 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-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAEuB3ApSzymExcc7Auzp7P-v%2BxqYWiRp9GyWF%3Dzt2mQrC14Y%2BQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAEuB3ApSzymExcc7Auzp7P-v%2BxqYWiRp9GyWF%3Dzt2mQrC14Y%2BQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLaZ_QjEJXDcJG3kjed9FjU1%2BbKZZLszwDWePRJ6G5St2A%40mail.gmail.com.

Reply via email to