I want to print out the results of a text file in ansible using cat. This is my code.
tasks:
- name: This option
script: "./getIt.py -s {{ myhostname }} -u {{ myuser }} -p {{ mypass }} >> ./It.txt"
shell: cat ./It.txt
when: user_option == 'L'
This however doesn't work. What am I doing wrong?
You are trying to call two different modules from a single task: script and shell. You need to break them up... one module per task! However, there's a better way to do it by capturing the output of the script with register, and using the debug module in a subsequent task to display it:
tasks:
- name: This option
script: "./getIt.py -s {{ myhostname }} -u {{ myuser }} -p {{ mypass }}"
register: script
when: user_option == 'L'
- name: stdout of getIt
debug: msg={{ script.stdout }}
when: script is defined and script|succeeded
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With