EagleDev
EagleDev

Reputation: 1865

Passing value of script variable to the playbook output

I'm quite new to Ansible so I'm still in learning curve. I'm looking for a way to retrieve a value from script's variable and use it further along with ansible-playbook command.

Saying I have a script I would like to retrieve $hostname info in target node. The script is run in a playbook. When a $HOSTNAME value returns, how can I pass it to my wrapper script so I can reference it with other list?

The script is as simple as follows:

HOSTNAME=$(hostname)
ECHO "$HOSTNAME"

Upvotes: 0

Views: 215

Answers (1)

WarrenG
WarrenG

Reputation: 1850

Assuming you are running a script with ansible in one task, you would register the output:

  tasks:
    - name: Echo value
      command: "echo Hello"
      register: command_output

Then in your next task, maybe you want to create a file for the hostname:

  - shell: "touch {{ item }} "
    with_items:
      - "{{ command_output.stdout_lines }}"

That's the basic structure - you don't say what command you want to run, but this should get you started. Here's a nice tutorial: http://www.mydailytutorials.com/ansible-register-variables/

Upvotes: 1

Related Questions