Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

core

ANSIBLE VERSION

ansible 2.2.0 (devel 5f12731797) last updated 2016/08/03 183842 (GMT +200)
lib/ansible/modules/core (detached HEAD db66758125) last updated 2016/08/03 183900 (GMT +200)
lib/ansible/modules/extras (detached HEAD 57c142b6ed) last updated 2016/08/03 184009 (GMT +200)
config file = /home/jpic/.ansible.cfg
configured module search path = [/home/jpic/ansible/library /usr/share/ansible]

CONFIGURATION

OS / ENVIRONMENT

SUMMARY

An exception is raised when:

adding a host with a given group name,

having a task with delegate_to: the_group_name

having a play for that group.

Pretty interresting indeed.

STEPS TO REPRODUCE

- hosts: localhost
tasks:
- add_host: name=testboot.lxc group=testboot # replace testboot.lxc by anything on which setup wil work
- raw: uname
delegate_to: testboot # obviously this is wrong, because we have no such host
when: false # however, this task is skipped, so not failing
- hosts: testboot # this triggers the exception, if you remove the skipped task above if works though
tasks:
- shell: uname -a

EXPECTED RESULTS

ACTUAL RESULTS

PLAYBOOK: test.yml *************************************************************
2 plays in test.yml
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [add_host] ****************************************************************
task path: /home/jpic/scratch/test.yml:6
creating host via 'add_host': hostname=testboot.lxc
changed: [localhost] => {
"add_host": {
"groups": [
"testboot"
],
"host_name": "testboot.lxc",
"host_vars": {
"group": "testboot"
}
},
"changed": true,
"invocation": {
"module_args": {
"group": "testboot",
"name": "testboot.lxc"
},
"module_name": "add_host"
}
}
TASK [raw] *********************************************************************
task path: /home/jpic/scratch/test.yml:7
skipping: [localhost] => {
"changed": false,
"skip_reason": "Conditional check failed",
"skipped": true
}
ERROR! Unexpected Exception: 'NoneType' object has no attribute 'name'
the full traceback was:
Traceback (most recent call last):
File "/home/jpic/env/src/ansible/bin/ansible-playbook", line 97, in <module>
exit_code = cli.run()
File "/home/jpic/env/src/ansible/lib/ansible/cli/playbook.py", line 154, in run
results = pbex.run()
File "/home/jpic/env/src/ansible/lib/ansible/executor/playbook_executor.py", line 144, in run
self._inventory.restrict_to_hosts(batch)
File "/home/jpic/env/src/ansible/lib/ansible/inventory/__init__.py", line 640, in restrict_to_hosts
self._restriction = [ h.name for h in restriction ]
AttributeError: 'NoneType' object has no attribute 'name'

However, if I use another faulty delegate_to that's not the name of the group in the next play then it doesn't crash:

---
- hosts: localhost
tasks:
- add_host: name=testboot.lxc group=testboot
- raw: uname
delegate_to: testbar # not testboot
when: false
- hosts: testboot
tasks:
- shell: uname -a

Result:

PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [add_host] ****************************************************************
changed: [localhost]
TASK [raw] *********************************************************************
skipping: [localhost]
PLAY [testboot] ****************************************************************
TASK [setup] *******************************************************************
ok: [testboot.lxc]
TASK [command] *****************************************************************
changed: [testboot.lxc]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
testboot.lxc : ok=2 changed=1 unreachable=0 failed=0

EXPECTED RESULT

So, I find it a bit weird that a skipped task can cause a subsequent play to fail (imagine the time it took to isolate this !). I'd be willing to contribute a fix, but I'm not sure what it should be:

fail a task if delegate_to is incorrect or is a valid group name, even if it is skipped,

ensure that delegate_to doesn't affect the global state if it's used with a value that's a valid group name but not a valid host name.

I suspect that other users might have been affected, but I don't know if anybody made it to isolate the issue, because it took quite some time I recon.

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

delegate_to

ANSIBLE VERSION

ansible 2.0.1.0
config file = /etc/ansible.cfg
configured module search path = /usr/share/ansible

CONFIGURATION

OS / ENVIRONMENT

N/A

SUMMARY

delegate_to: ignore when:

More specifically delegate_to is evaluated before when could even skip the task.

STEPS TO REPRODUCE

- hosts: localhost
tasks:
- debug: msg="blah"
delegate_to: false
when: false

(In my case delegate_to was a variable [the IP of a "master" node], I had hard time figuring out what was wrong)

EXPECTED RESULTS

task skipped

ACTUAL RESULTS

Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 86, in <module>
sys.exit(cli.run())
File "/usr/lib/python2.7/dist-packages/ansible/cli/playbook.py", line 150, in run
results = pbex.run()
File "/usr/lib/python2.7/dist-packages/ansible/executor/playbook_executor.py", line 140, in run
result = self._tqm.run(play=play)
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_queue_manager.py", line 238, in run
play_return = strategy.run(iterator, play_context)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/strategy/linear.py", line 229, in run
task_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, host=host, task=task)
File "/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py", line 343, in get_vars
all_vars['ansible_delegated_vars'] = self._get_delegated_vars(loader, play, task, all_vars)
File "/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py", line 483, in _get_delegated_vars
include_hostvars=False,
File "/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py", line 247, in get_vars
all_vars = combine_vars(all_vars, host.get_vars())
File "/usr/lib/python2.7/dist-packages/ansible/inventory/host.py", line 128, in get_vars
results['inventory_hostname_short'] = self.name.split('.')[0]
AttributeError: 'bool' object has no attribute 'split'