Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print out contents of a file using ansible

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?

like image 760
user3796292 Avatar asked Sep 06 '16 01:09

user3796292


1 Answers

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
like image 53
mwp Avatar answered Oct 01 '22 08:10

mwp