Under Ansible 2.2.1 and python 2.7 I have a playbook for generically creating a docker container and then adding it as a host (using the docker connection plugin of course):
- name: Start specified container
gather_facts: no
hosts: localhost
connection: local
vars:
container_name: openshift_ansible_test_{{ scenario }}
l_vars: >
{{
l_host_vars | default({}) | combine({
“ansible_connection”: “docker”,
“name”: container_name,
“groups”: l_groups if l_groups else “OSEv3,masters,nodes”,
})
}}
tasks: - debug: var=l_vars
- name: start container
docker_container:
name: “{{ container_name }}”
image: “{{ image }}”
command: sleep 1800
recreate: yes
when: False - name: add host
add_host: “{{ l_vars }}”
The idea is to be able to pass in l_host_vars with variable properties for add_host. l_vars gets populated as expected, so the debug looks like this:
ok: [localhost] => {
“l_vars”: {
“ansible_connection”: “docker”,
“deployment_type”: “origin”,
“groups”: “OSEv3,masters,nodes,etcd”,
“name”: “openshift_ansible_test_preflight_fail_all”
}
}
However the add_host task does not like it as parameters and there does not seem to be any variation that will get it to work:
creating host via ‘add_host’: hostname=None
ERROR! Unexpected Exception: unsupported operand type(s) for +: ‘NoneType’ and ‘str’
the full traceback was:
Traceback (most recent call last):
File “/bin/ansible-playbook”, line 103, in
exit_code = cli.run()
File “/usr/lib/python2.7/site-packages/ansible/cli/playbook.py”, line 159, in run
results = pbex.run()
File “/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py”, line 154, in run
result = self._tqm.run(play=play)
File “/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py”, line 282, in run
play_return = strategy.run(iterator, play_context)
File “/usr/lib/python2.7/site-packages/ansible/plugins/strategy/linear.py”, line 278, in run
results += self._wait_on_pending_results(iterator)
File “/usr/lib/python2.7/site-packages/ansible/plugins/strategy/init.py”, line 577, in _wait_on_pending_results
results = self._process_pending_results(iterator)
File “/usr/lib/python2.7/site-packages/ansible/plugins/strategy/init.py”, line 478, in _process_pending_results
self._add_host(new_host_info, iterator)
File “/usr/lib/python2.7/site-packages/ansible/plugins/strategy/init.py”, line 598, in _add_host
self._inventory.get_host_vars(new_host)
File “/usr/lib/python2.7/site-packages/ansible/inventory/init.py”, line 771, in get_host_vars
return self._get_hostgroup_vars(host=host, group=None, new_pb_basedir=new_pb_basedir, return_results=return_result
s)
File “/usr/lib/python2.7/site-packages/ansible/inventory/init.py”, line 842, in _get_hostgroup_vars
elif group is None and any(map(lambda ext: host.name + ext in self._host_vars_files, C.YAML_FILENAME_EXTENSIONS)):
File “/usr/lib/python2.7/site-packages/ansible/inventory/init.py”, line 842, in
elif group is None and any(map(lambda ext: host.name + ext in self._host_vars_files, C.YAML_FILENAME_EXTENSIONS)):
TypeError: unsupported operand type(s) for +: ‘NoneType’ and ‘str’
Any idea how I can get this to do what I want? TIA