Pipe process to target stdin in Ansible Playbook

Viewed 1039

How can I pipe the stdout of a command executed on the host (admin) machine to the stdin of a process on the target (remote) machine, using a playbook?

To illustrate, imagine I wanted to do the following via Ansible instead of ssh (echo and dd are arbitrary placeholders for the actual scripts)

echo hello world | ssh remote 'dd of=message.txt'
1 Answers

Using the following task composition:

    - command: '<remote command>'
      args:
        stdin: "{{ lookup('pipe','<local command>') }}"

For example:

    - command: 'dd of=message.txt'
      args:
        stdin: "{{ lookup('pipe','echo hello world') }}"

References:

Related