Weird behaviour when embedding ansible

Hi,

I ran across a weird effect when integrating ansible in my program (running a YAML playbook, returning data to my process).

Apparently host variables may leak between playbook invocations.

Test script:

https://gist.github.com/gnosek/6528590

Note that on the second run (with name='name2') the first task from the play gets executed with old variables. Depending on what exactly you put there, you either get name=name1, or fqdn=name1.example.com.

Works the same, regardless of gather_facts being true/false. Also note that in this one invocation the header and module args disagree:

TASK: [debug msg="fqdn=name2.example.com"] ***
ok: [localhost] => {"msg": "fqdn=name1.example.com"}

I understand this isn't the most popular way to run ansible, but still it means that there are some globals lurking, which shouldn't really be there (otherwise in the second run there would be no trace of 'name1' any more).

Is this considered a bug, or should I just stick debug: msg=workaround at the beginning of my playbooks?

Best regards,
  Grzegorz Nosek

Host variables are intentionally shared between playbook executions – this includes register statements and facts, so fact gathering only needs to be done once.

Feature, not a bug :slight_smile: