Ansible: Defined object getting 'dict object' has no attribute

Viewed 38

I'm creating a kickstart file with Ansible. The playbook fails when I try to add --grow to the lv I'm creating.

This works in my j2.cfg file when I define the pv:

{% for part in item.partitions|default([]) %}
part {{ part.name }} --size {{ part.size_mib }}{{ ' --asprimary' if part.primary else '' }}{{ ' --grow' if part.grow else '' }}{% if part.fstype is defined %} --fstype={{ part.fstype }}{% endif %} --ondrive={{ part.drive }}
{% endfor %}
{% endif %}

Then fails when I define the lv:

{% for vol in item.logvols|default([]) %}
logvol {{ vol.mount }} --name={% if vol.mount != '/' %}lv_{{ vol.mount | regex_replace('^/', '') | replace('-','__') | replace(' ','___') | replace('/','_') }}{% else %}lv_root{% endif %} --vgname=vg_{{ item.hostname | replace('-','_') }}_{{ vol.volgroup }} --fstype={{ vol.fstype | default('xfs') }} --size={{ vol.size_mib }}{{ ' --grow' if vol.grow else '' }}
{% endfor %}

When I run the ansible playbook with verbose it show that the object is defined.

"logvols": [
                    {
                        "fstype": "xfs", 
                        "grow": true, 
                        "mount": "/", 
                        "size_mib": 1, 
                        "volgroup": "main"

But errors with:

"msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'grow'"

If I take out the {{ ' --grow' if vol.grow else '' }} from logvols it works and creates the file with --grow in the partition section.

For the life of me I can't determine why it works once but not again.

Here are how the variables are defined.

partitions:
  - { name: /boot, fstype: ext2, primary: true, grow: false, size_mib: "{{ 2*1024 | int }}", drive: sda }
  - { name: pv.01, drive: sda, fstype: lvmpv, primary: true, size_mib: 1, grow: true }

volgroups:
  - { name: main, device: pv.01 }

logvols:
  - { mount: swap, fstype: swap, volgroup: main, size_mib: "{{ 4*1024 | int }}" }
  - { mount: /, volgroup: main, size_mib: 1, grow: true, fstype: xfs }
0 Answers
Related