# ansible 1.9.4 to 2.4.1.0 migration issue

**URL:** <https://forum.ansible.com/t/ansible-1-9-4-to-2-4-1-0-migration-issue/26135>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [November 27, 2017, 3:00am UTC](https://forum.ansible.com/t/ansible-1-9-4-to-2-4-1-0-migration-issue/26135 "2017-11-27T03:00:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_V](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@George\_V](https://forum.ansible.com/u/George_V)\
**Post date:** [November 27, 2017, 3:00am UTC](https://forum.ansible.com/t/ansible-1-9-4-to-2-4-1-0-migration-issue/26135/1 "2017-11-27T03:00:35Z")

</div>

Hi all,

I have been avoiding to upgrade Ansible 1.9.4 on Centos 6 for the past few months, however since the upgrade project is again on my desk, I am actively working through the warnings and errors e.g. substituting include: statements in tasks with import\_tasks:, editing playbooks and removing duplicate when: statements and so on.

There is one issue that I cannot resolve, it seems. I maintain a list of vars for each server in the event that I need to rebuild the server ( NODES file below ). It essentially is a list of settings for each server like sshd extra options, interface and cacti settings and so on. The issue is that in 2.4 I seem not to be able to run this playbook as I was able in 1.9.4. I see that jinja2 in when statement gets a warning.

Any ideas on how I would be able to run this playbook ? I am willing to redo the nodes file if there is a better way to do this. Looks like jinja2 in when statements is not supported any longer ?  
Thank you

Version details:

root [/etc/ansible/deployment]# rpm -q ansible  
ansible-2.4.1.0-2.el6.noarch

root [/etc/ansible/deployment]# rpm -qa | egrep jinja  
python-jinja2-26-2.6-3.el6.noarch  
python-jinja2-2.7.2-1.el6.noarch # \<— This was needed for filters

root [/etc/ansible/deployment]# rpm -q centos-release  
centos-release-6-9.el6.12.3.x86\_64

### VARS file

hname: “‘{{ inventory\_hostname }}’”

hostname\_hostname: “{{inventory\_hostname}}”  
hostname\_shortname: “{{inventory\_hostname.split(‘.’)[0]}}”

# remove dash from host name as Ansible cannot handle it properly in vars

hostname\_mounts: “{{hostname\_shortname.replace(‘-’,‘’)}}”  
hostname\_short: “{{hostname\_shortname.replace(‘-’,‘’)}}”

### NODES file

nodes:  
umsrv3s1: # \<— short hostname  
ifconfig: # \<— interface info

- { iface: ‘eth0’, IP: ‘91.X.Y.Z1’, netmask: ‘255.255.255.0’, gw: ‘91.X.Y.G1’, enabled: ‘1’ }  
mounts:
- {source: ‘proc’, target: ‘/proc’, opts: ‘defaults,hidepid=1’, fstype: ‘proc’}  
cacti:
- { enabled: ‘1’, tree: ‘Citi1’, template: ‘ucd/net SNMP Host’ }  
httpd:
- { enable: false }  
yumextra: # \<— extra packages for this server only
- { packages: [ansible-inventory-puppetdb, ansible-cmdb, VMware-vSphere-CLI, python-psphere, python-sphere, python-pyvmomi] }  
sshdextra: # \<— extra sshd options for this server
- { name: ‘MaxSessions’, value: ‘6’}
- { name: ‘MaxStartups’, value: ‘100:30:150’}

# DisableForwarding added in 7.4

- { name: ‘DisableForwarding’, value: ‘yes’}

umsrv3s2:  
ifconfig:

- { iface: ‘eth0’, IP: ‘91.X.Y.Z2’, netmask: ‘255.255.255.0’, gw: ‘91.X.Y.G1’, enabled: ‘1’ }  
mounts:
- {source: ‘proc’, target: ‘/proc’, opts: ‘defaults,hidepid=1’, fstype: ‘proc’}  
cacti:
- { enabled: ‘1’, tree: ‘City1’, template: ‘ucd/net SNMP Host’ }  
yumextra:
- { packages: }  
sshdextra:   
httpd:
- { enable: false }  
[…]

### TASKS

- name: setfacts - set hostname vars  
set\_fact:  
hostname\_short\_nodash: “{{ inventory\_hostname.split(‘.’)[0].replace(‘-’,‘’) }}”  
hostname\_short: “{{inventory\_hostname.split(‘.’)[0]}}”  
tags: [setfacts]

- name: yum - set\_fact - get list of host-specific packeges to be installed  
set\_fact:  
\_\_packages: “{{ item.packages }}”  
**with\_items: nodes.{{hostname\_mounts}}.yumextra**  
**when: nodes.{{hostname\_mounts}}.yumextra is defined**  
tags: [setfacts, yum]

- name: yum - echo \_\_packages  
debug: var=\_\_packages  
when: nodes.{{hostname\_mounts}}.yumextra is defined  
tags: [setfacts, yum]

- name: yum - set\_fact - get list of host-specific packeges to be installed  
set\_fact:  
\_\_packages: “{{ item.packages }}”  
with\_items: nodes.{{hostname\_mounts}}.yumextra  
when: nodes.{{hostname\_mounts}}.yumextra is defined  
tags: [setfacts, yum]

- name: yum - echo \_\_packages  
debug: var=\_\_packages  
when: nodes.{{hostname\_mounts}}.yumextra is defined  
tags: [setfacts, yum]

/usr/bin/ansible-playbook -l `hostname -f` -c local /etc/ansible/deployment/deployment.yml --vault-password-file .vault --tags=setfacts  
[…]

TASK [yum - set\_fact - get list of host-specific packeges to be installed] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: nodes.{{hostname\_mounts}}.yumextra is defined

fatal: [umsrv10]: FAILED! =\> {“failed”: true, “msg”: “The task includes an option with an undefined variable. The error was: ‘ansible.utils.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘packages’\n\nThe error appears to have been in ‘/etc/ansible/deployment/tasks/setfacts.yml’: line 49, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# YUM #\n- name: yum - set\_fact - get list of host-specific packeges to be installed\n ^ here\n\nexception type: \<class ‘ansible.errors.AnsibleUndefinedVariable’\>\nexception: ‘ansible.utils.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘packages’”}

---

<div class="post-metadata">

**Author:** ![tkuratom](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@tkuratom](https://forum.ansible.com/u/tkuratom)\
**Post date:** [November 27, 2017, 5:47am UTC](https://forum.ansible.com/t/ansible-1-9-4-to-2-4-1-0-migration-issue/26135/2 "2017-11-27T05:47:07Z")

</div>

Try nodes[hostname\_mounts][“yumextra”]

-Toshio

---

<div class="post-metadata">

**Author:** ![George\_V](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@George\_V](https://forum.ansible.com/u/George_V)\
**Post date:** [November 27, 2017, 6:46pm UTC](https://forum.ansible.com/t/ansible-1-9-4-to-2-4-1-0-migration-issue/26135/3 "2017-11-27T18:46:27Z")

</div>

Toshi,

Thank you for pointing me in the right direction, I was able to move forward with this, for posterity this is what I ended up with:

- hosts: all  
gather\_facts: yes  
become: no

vars:  
hostname\_shortname: “{{inventory\_hostname.split(‘.’)[0]}}”  
hostname\_mounts: “{{hostname\_shortname.replace(‘-’,‘’)}}”

nodes:  
umsrv10:  
packages: [drssl, ansible-cmdb]

tasks:

- name: yum - echo \_\_packages  
debug: var=“{{item}}”  
with\_items: nodes[hostname\_mounts][“packages”]

- name: yum - install main rpms  
yum: name={{item}} state=installed  
with\_items:

- “{{nodes[hostname\_mounts][‘packages’]}}”

root@umsrv10[/etc/ansible/playbooks]# /usr/bin/ansible-playbook -l `hostname -f` -c local /etc/ansible/playbooks/setfacts3.yml

PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[umsrv10.sec.hostopia.com](http://umsrv10.sec.hostopia.com)]

TASK [yum - echo \_\_packages] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [umsrv10\*\*\*\*\*] =\> (item=nodes[hostname\_mounts][“packages”]) =\> {  
“item”: “nodes[hostname\_mounts]["packages"]”,  
“nodes[hostname\_mounts]["packages"]”: [  
“drssl”,  
“ansible-cmdb”  
]  
}

TASK [yum - install main rpms] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[umsrv10.sec.hostopia.com](http://umsrv10.sec.hostopia.com)] =\> (item=[u’drssl’, u’ansible-cmdb’])

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
umsrv10\*\*\*\*\* : ok=3 changed=0 unreachable=0 failed=0
