Skip to content

Instantly share code, notes, and snippets.

@madsonic
Last active August 1, 2019 02:25
Show Gist options
  • Select an option

  • Save madsonic/1b908998ea9cc432613695ebf050fb83 to your computer and use it in GitHub Desktop.

Select an option

Save madsonic/1b908998ea9cc432613695ebf050fb83 to your computer and use it in GitHub Desktop.
ansible tips and tricks
# render template via ansible module
$ ansible all -i "localhost," \
-c local \
-m template \
-a "src=test.txt.j2 dest=./test.txt" \
--extra-vars='{"users": ["Mike", "Smith", "Klara", "Alex"]}'
# render template via playbook
- hosts: 127.0.0.1
tasks:
- name: Test jinja2template
template: src=test.j2 dest=test.conf
ansible-playbook jinja2test.yml --check --diff --connection=local
# handle machine restarts/connection restart etc
# if these tasks are handlers, let them listen to the same topic while having the
# 'wait' task to be after the task responsible for the connection abortion
- name: some task that will affect control machine to target host connection
...
async: 1 # any value > 0
poll: 0
- name: wait for connection
wait_for_connection:
timeout: 60
delay: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment