
This playbook demonstrates how you can redirect shell output to a local file
Inventory
Our inventory.ini
file:
1
2
| [localhost]
localhost
|
The Script
Our script: /tmp/foo
1
2
3
| #!/usr/bin/env bash
echo "foo"
echo "bar"
|
Apply executable permissions:
Playbook
Our playbook: debug.yml
1
2
3
4
5
6
7
| ---
- hosts: localhost
tasks:
- shell: /tmp/foo
register: foo_result
ignore_errors: True
- local_action: copy content= dest=file
|
Running
Running the Ansible Playbook:
1
2
3
4
5
6
7
8
9
10
11
12
| $ ansible-playbook -i inventory.ini debug.yml
PLAY [localhost] ********************************************************************************************************************************************************************
TASK [shell] ************************************************************************************************************************************************************************
changed: [localhost]
TASK [copy] *************************************************************************************************************************************************************************
changed: [localhost -> localhost]
PLAY RECAP **************************************************************************************************************************************************************************
localhost : ok=2 changed=2 unreachable=0 failed=0
|
View the local saved file:
Read More
For more content on Ansible check out my Ansible category