Skip to content

Instantly share code, notes, and snippets.

@gnosek
Last active November 6, 2018 03:12
Show Gist options
  • Save gnosek/6528590 to your computer and use it in GitHub Desktop.
Save gnosek/6528590 to your computer and use it in GitHub Desktop.
Weird behaviour in ansible
from ansible import playbook, callbacks
def run_playbook(path, extra_vars):
stats = callbacks.AggregateStats()
playbook_cb = callbacks.PlaybookCallbacks(verbose=1)
runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=1)
pb = playbook.PlayBook(
playbook=path,
stats=stats,
callbacks=playbook_cb,
runner_callbacks=runner_cb,
extra_vars=extra_vars)
return pb.run()
def test(path):
run_playbook(path, {'name': 'name1'})
run_playbook(path, {'name': 'name2'})
if __name__ == '__main__':
import sys
test(sys.argv[1])
---
- hosts: localhost
gather_facts: false
vars:
- fqdn: "{{name}}.example.com"
tasks:
- debug: msg="fqdn={{fqdn}}"
- debug: msg="fqdn={{fqdn}}"
- shell: echo fqdn={{fqdn}}
- shell: echo name={{name}}
PLAY [localhost] **************************************************************
TASK: [debug msg="fqdn=name1.example.com"] ************************************
ok: [localhost] => {"msg": "fqdn=name1.example.com"}
TASK: [debug msg="fqdn=name1.example.com"] ************************************
ok: [localhost] => {"msg": "fqdn=name1.example.com"}
TASK: [shell echo fqdn=name1.example.com] *************************************
changed: [localhost] => {"changed": true, "cmd": "echo fqdn=name1.example.com ", "delta": "0:00:00.001438", "end": "2013-09-11 19:34:08.013751", "rc": 0, "start": "2013-09-11 19:34:08.012313", "stderr": "", "stdout": "fqdn=name1.example.com"}
TASK: [shell echo name=name1] *************************************************
changed: [localhost] => {"changed": true, "cmd": "echo name=name1 ", "delta": "0:00:00.001472", "end": "2013-09-11 19:34:08.099415", "rc": 0, "start": "2013-09-11 19:34:08.097943", "stderr": "", "stdout": "name=name1"}
PLAY [localhost] **************************************************************
TASK: [debug msg="fqdn=name2.example.com"] ************************************
ok: [localhost] => {"msg": "fqdn=name1.example.com"}
TASK: [debug msg="fqdn=name2.example.com"] ************************************
ok: [localhost] => {"msg": "fqdn=name2.example.com"}
TASK: [shell echo fqdn=name2.example.com] *************************************
changed: [localhost] => {"changed": true, "cmd": "echo fqdn=name2.example.com ", "delta": "0:00:00.001478", "end": "2013-09-11 19:34:08.278582", "rc": 0, "start": "2013-09-11 19:34:08.277104", "stderr": "", "stdout": "fqdn=name2.example.com"}
TASK: [shell echo name=name2] *************************************************
changed: [localhost] => {"changed": true, "cmd": "echo name=name2 ", "delta": "0:00:00.001466", "end": "2013-09-11 19:34:08.366428", "rc": 0, "start": "2013-09-11 19:34:08.364962", "stderr": "", "stdout": "name=name2"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment