Reputation: 14505
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?
Upvotes: 0
Views: 5049
Reputation: 3769
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 }}"
Upvotes: 4