# Weird behaviour when embedding ansible

**URL:** <https://forum.ansible.com/t/weird-behaviour-when-embedding-ansible/13455>\
**Category:** Ansible Project\
**Created:** [September 11, 2013, 7:37pm UTC](https://forum.ansible.com/t/weird-behaviour-when-embedding-ansible/13455 "2013-09-11T19:37:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grzegorz\_Nosek](https://avatars.discourse-cdn.com/v4/letter/g/5daacb/32.png) [@Grzegorz\_Nosek](https://forum.ansible.com/u/Grzegorz_Nosek)\
**Post date:** [September 11, 2013, 7:37pm UTC](https://forum.ansible.com/t/weird-behaviour-when-embedding-ansible/13455/1 "2013-09-11T19:37:31Z")

</div>

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](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,  
&nbsp;&nbsp;Grzegorz Nosek

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 12, 2013, 5:39pm UTC](https://forum.ansible.com/t/weird-behaviour-when-embedding-ansible/13455/2 "2013-09-12T17:39:37Z")

</div>

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 🙂
