-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent variable dereferences depending on number of forks #4239
Comments
As discussed on the mailing list, you should not mix host variables in your role directories as Ansible will try to load them from other paths. However I've noticed that we didn't implement the feature I was thinking of yet, so my original explanation seems to be wrong: #2958 This is probably the case of something not doing a copy of a value somewhere. |
I just moved the variable files out of the role path and updated |
Ok, so I reverted commit 576962d in order to vary the number of forks. Additionally, I added some debug prints to I ran the test with
As can be seen in the last |
@fgtham I can not reproduce this with 1.3.2 or latest devel, which might be me overlooking something or not understanding your description. If you could attach/comment an updated reproducer script, i'll take another stab at it. |
I just upgraded to v1.3.3. The issue remains. Here's an updated test case. Run it, change into
The first run passes, the second run fails.
|
@fgtham Is this the behavior you expected to see? ... jtanner@u1304:~/issues/4239-variable-derefernce-forks/code2/ansible_test$ ansible-playbook -i hosts site.yml PLAY [vm_guests] ************************************************************** 127.0.0.3: importing /home/jtanner/issues/4239-variable-derefernce-forks/code2/ansible_test/vars/srv.yml 127.0.0.4: importing /home/jtanner/issues/4239-variable-derefernce-forks/code2/ansible_test/vars/srx.yml TASK: [vm | delegation pass] ************************************************** changed: [127.0.0.4] changed: [127.0.0.3] TASK: [vm | template upload] ************************************************** ok: [127.0.0.3] ok: [127.0.0.4] TASK: [vm | delegation fail] ************************************************** changed: [127.0.0.4] changed: [127.0.0.3] PLAY RECAP ******************************************************************** 127.0.0.3 : ok=3 changed=2 unreachable=0 failed=0 127.0.0.4 : ok=3 changed=2 unreachable=0 failed=0 jtanner@u1304:~/issues/4239-variable-derefernce-forks/code2/ansible_test$ ansible-playbook -i hosts --forks 1 site.yml PLAY [vm_guests] ************************************************************** 127.0.0.3: importing /home/jtanner/issues/4239-variable-derefernce-forks/code2/ansible_test/vars/srv.yml 127.0.0.4: importing /home/jtanner/issues/4239-variable-derefernce-forks/code2/ansible_test/vars/srx.yml TASK: [vm | delegation pass] ************************************************** changed: [127.0.0.3] changed: [127.0.0.4] TASK: [vm | template upload] ************************************************** ok: [127.0.0.3] ok: [127.0.0.4] TASK: [vm | delegation fail] ************************************************** fatal: [127.0.0.3] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue fatal: [127.0.0.4] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue FATAL: all hosts have already failed -- aborting PLAY RECAP ******************************************************************** to retry, use: --limit @/home/jtanner/site.retry 127.0.0.3 : ok=2 changed=1 unreachable=1 failed=0 127.0.0.4 : ok=2 changed=1 unreachable=1 failed=0 |
Yes, this is the bug I encountered. The playbook's result only depends on the number of parallel ansible processes, which doesn't make sense. If you increase logging with |
I was able to see more of what is going on via the debug module ... PLAY [vm_guests] ************************************************************** 127.0.0.3: importing /home/jtanner/issues/4239-variable-derefernce-forks/code2/ansible_test/vars/srv.yml 127.0.0.4: importing /home/jtanner/issues/4239-variable-derefernce-forks/code2/ansible_test/vars/srx.yml TASK: [vm | debug var=vm] ***************************************************** ok: [127.0.0.3] => { "item": "", "vm": { "foo": "bar", "host_system": "127.0.0.2" } } ok: [127.0.0.4] => { "item": "", "vm": { "foo": "baz", "host_system": "127.0.0.2" } } TASK: [vm | delegation pass] ************************************************** changed: [127.0.0.3] changed: [127.0.0.4] TASK: [vm | template upload] ************************************************** ok: [127.0.0.3] ok: [127.0.0.4] TASK: [vm | debug var=vm] ***************************************************** ok: [127.0.0.3] => { "item": "", "vm": { "foo": "bar" } } ok: [127.0.0.4] => { "item": "", "vm": { "foo": "baz" } } TASK: [vm | delegation fail] ************************************************** fatal: [127.0.0.3] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue fatal: [127.0.0.4] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue FATAL: all hosts have already failed -- aborting So after the template module call, "vm" looses it's "host_system" key. If I comment out the template task in main.yml, the error disappears. I'll keep digging. |
The first problem I found is that this syntax won't work ... vars_files: - "vars/{{ name }}.yml" The templating code doesn't have vars populated when it goes to replace the line ... vm | template src=test.j2 dest=/tmp/{{vm.host_system}}-test.txt :::: ERROR 'vm' is undefined {'_original_file': '/home/jtanner/issues/4239-variable-derefernce-forks/code-fix/ansible_test/roles/vm/tasks/main.yml', 'always_run': False, 'changed_when': None, 'delegate_to': None, 'failed_when': None, 'ignore_errors': False, 'inventory_dir': '/home/jtanner/issues/4239-variable-derefernce-forks/code-fix/ansible_test', 'inventory_file': 'hosts', 'item': '', 'register': None} #4616 Details this as a feature request. I know the playbook layout is a reduced example to show your usecase, but what is the intent for trying to load vars_files that way? Can you elaborate a bit more? |
I use ansible to create and manage a number of virtual machines on multiple servers. The configuration parameters that are identical for most of the VMs have been placed under Here's the VM guest role definition:
The Edit: what I don't get is: if you say that "the templating code doesn't have vars populated when it goes to replace the line ...", why does it appear to work with a number of forks greater than one? |
#4239 (comment) is resolved. |
Preliminary patch:
|
@fgtham I know it took a long time, but I think this is finally fixed. If you are still able, try out your test playbook with devel. It's working for me when running your test scripts without any modification. |
I have recently upgraded to ansible 1.3.2 from the release/1.3.2 branch. This upgrade broke my playbooks.
git bisect
identified commit 576962d as the first bad commit. This commit changes the number of forks in relation to the number of hosts. As it turns out, this commit did not introduce the bug I encountered, but merely unmasked it.Unfortunately, the most reduced example I managed to create is not really minimal. At the end of the comment there's a script to create the files I mention here, so that you can easily reproduce the problem. Note that you will need to set
hash_behaviour = merge
In youransible.cfg
:With ansible 1.3.2, the playbook works like expected when called with:
If I limit the number of forks to exactly 1, execution aborts with an error:
As can be seen in the last line, ansible cannot dereference
vm.host_system
any longer.The same behaviour occurs with the following invocation, as it implicitly sets the number of forks to 1:
With versions prior to commit 576962d, these invocations result in the playbook being executed successfully:
However, these invocations abort with errors, as
vm.host_system
cannot be dereferenced any longer:In other words: if the number of forks is greater than 1, variable dereference works, whereas it does not work if the number of forks is equal to one. As commit 576962d caps the number of forks if it it greater than the number of hosts, it unmasked the problem.
I would expect identical behaviour no matter how many processes are being forked.
In the file
role.vm.yml
, if I change the filename of the vars_file to be included to something fixed likevars_files: [ roles/vm/vars/srv.yml ]
, the playbook will execute successfully every single time.If I remove the template task, the error is gone, too.
My python-fu is not strong enough to figure out what's going on.
PS: Here's the script I mentioned to create the files in order to reproduce the issue:
The text was updated successfully, but these errors were encountered: