Skip to content

Instantly share code, notes, and snippets.

@mageddo
Last active January 26, 2019 16:37
Show Gist options
  • Save mageddo/82ac1b80d30a76a7dcaac602258ee21c to your computer and use it in GitHub Desktop.
Save mageddo/82ac1b80d30a76a7dcaac602258ee21c to your computer and use it in GitHub Desktop.
Run Command on Another Server and register output on variable
#!/bin/bash
ansible-playbook -i "localhost," -c local playbook.yml
# https://stackoverflow.com/questions/33896847/how-do-i-set-register-a-variable-to-persist-between-plays-in-ansible
- hosts: all
tasks:
- command: /bin/echo "this is a test"
delegate_to: localhost
register: foo
- debug: var=foo
- debug:
msg: "{{ foo['stdout'] }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment