0

I want to run some command that return some data and process these data somehow with a script that is located on ansible server. How could I do that?

For example:

I want to run

ansible all -a "cat /etc/redhat-release"

Then I want to call script called version_parser.py (located on local ansible server, not host where ansible is executing the command) with parameters name_of_server and pipe the output of this call as input.

So that in reality I get something similar like

ssh server1 "cat /etc/redhat-release" | version_parser.py server1
ssh server2 "cat /etc/redhat-release" | version_parser.py server2
...

What is most easy approach to do something like this?

1 Answer 1

4

You could run the remote command and store the result in a variable. Next you can run a local_action and execute your local script with the stored variable:

---
- name: Run remote command
  command: "bash -c 'ls -l /etc/init.d/a* | grep -c app'"
  register: store

- name: Run result against local script
  local_action: "shell echo '{{ store.stdout }}' | /path/to/local/parser.py {{ inventory_hostname }}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.