nested include_vars not overriding a variable between each loops

59 views
Skip to first unread message

Aalaesar

unread,
Aug 4, 2016, 1:23:07 PM8/4/16
to Ansible Project
Hello,
I'm actually making a role for managing  bind configuration but i'm stuck with what seems to be a regression  in my role.

briefly :
Using ansible 2.1.1.0.
 The role user should be able to give a yml file containing a dict of ressource records named "records" for each zone
Each zone is declared in a list named "zones"

for keeping the code DRY and reusable, I divided the tasks in multiple files using include in main.yml and blocks

The problem appears during the zone data generation.
this step is an include task.yml with_items :

extract of main.yml :
 # generate/copy zones data
- include: create_zone_db.yml
  with_items
: "{{ zones }}"
  tags
: setup_zones


extract of create_zone_db.yml
---
- block:
 
- set_fact: "zone_filename=db.{{ item.name }}"

  - name: Loading zone content for {{ item.name }} from {{ item.ymlfile }}
    include_vars
: "{{ item.ymlfile }}"

 
 
- name: Setup zones files for {{ item.name }} and verify
   
template:
    src
: db.zones.template.j2
    dest
: "{{ bind_zones_dir }}/{{ zone_filename }}"
    owner
: "{{ bind_user }}"
   
group: "{{ bind_group }}"
    mode
: 0644
    validate
: "/usr/sbin/named-checkzone {{ item.name }} %s"
  notify
: reload bind
 
when: item.ymlfile is defined


It works fine on the first loop with the first element in the "zones" list
but, if another element contains another ymlfile field,

on the next loop, the include_vars pass over the correct file but
the records dict is not overrided with the dict provided in the second and therefore the next zone has incorrect zone data.

example : 
in the user playbook :
---
 host
: localhost
 roles
:
 
- role: manage-bind
   zones
:
     
- name: example.com
       type
: master
       ymlfile
: example.com.yml
     
- name: test.org
       type
: master
       ymlfile
: test.org.yml


in example.com.yml
---
records
:
  ttl
: 3d
  SOA
:
    serial
: 2016080401
    ns
: srvdns01.example.com.
    email
: admin.example.com.
    refresh
: 12h
   
retry: 30m
    expire
: 3w
   negative
: 2h30m
  NS
:
   
- srvdns01.example.com.
  A
:
   
127.0.0.1:
   
- '@'
   
- srvdns01.example.com.


in test.org.yml
---
records:
  ttl: 3d
  SOA:
    serial: 2016080401
    ns: host.test.org.
    email: root.test.org.
  NS:
    - host.test.org.
  A:
    127.0.0.1:
      - '@'
      - host.test.org.

expected result for the second loop : 

records:
  ttl: 3d
  SOA:
    serial: 2016080401
    ns: host.test.org.
    email: root.test.org.
  NS:
    - host.test.org.
  A:
    127.0.0.1:
      - '@'
      - host.test.org.

actual result : 
records:
  ttl: 3d
  SOA:
    serial: 2016080401
    ns: host.test.org.
    email: root.test.org.
    refresh: 12h
    retry: 30m
    expire: 3w
    negative: 2h30m
  NS:
    - host.test.org.
  A:
    127.0.0.1:
      - '@'
      - host.test.org.

It worked a month ago with records being a list instead of dict but when roll-backed to list type, I had the same issue.
I have tested with and without blocks and without include with same results
I looked over Variable Precedence in ansible doc without fiding anything explicit.

At this point I am clueless.
I don't know if i messed up with something, or if a found an issue with ansible or if my design is bad...

Any help Ansible experts ?
Thanks.
Aalaesar/
Reply all
Reply to author
Forward
0 new messages