Hi - I've got a few questions....I have a variable (dictionary with lists I 
think is what it is? Is this the correct name/term?)

dns_nat_dc1_records:
  - { zone: 'test.com', name: 'server1', target: '192.168.1.10', type: 
'ARecord', state: 'present' }
  - { zone: 'test.com', name: 'server2', target: '192.168.1.11', type: 
'ARecord', state: 'present' }
  - { zone: 'test.com', name: 'crl', target: '192.168.1.12', type: 'ARecord'
, state: 'present' }
  - { zone: 'test.com', name: 'server1', target: '192.168.100.10', type: 
'ARecord', state: 'absent' }
  - { zone: 'test.com', name: 'server2', target: '192.168.100.11', type: 
'ARecord', state: 'absent' }
  - { zone: 'test.com', name: 'crl', target: '192.168.100.12', type: 
'ARecord', state: 'absent' }


  
dns_nat_dc2_records:
  - { zone: 'test.com', name: 'server1', target: '192.168.100.10', type: 
'ARecord', state: 'present' }
  - { zone: 'test.com', name: 'server2', target: '192.168.100.11', type: 
'ARecord', state: 'present' }
  - { zone: 'test.com', name: 'crl', target: '192.168.100.12', type: 
'ARecord', state: 'present' }
  - { zone: 'test.com', name: 'server1', target: '192.168.1.10', type: 
'ARecord', state: 'absent' }
  - { zone: 'test.com', name: 'server2', target: '192.168.1.11', type: 
'ARecord', state: 'absent' }
  - { zone: 'test.com', name: 'crl', target: '192.168.1.12', type: 'ARecord'
, state: 'absent' }

I have a couple of plays.....

- name: Ensure DNS NAT A/CNAME Records are present/absent for running in DC1
win_dsc:
resource_name: xDnsRecord
Zone: "{{ item.zone }}"
Name: "{{ item.name }}"
Target: "{{ item.target }}"
Type: "{{ item.type }}"
Ensure: "{{ item.state }}"
loop: "{{ dns_nat_dc1_records }}"

when: (env == 'dev' or env == 'stg') and active_site == 'dc1'

- name: Ensure DNS NAT A/CNAME Records are present/absent for running in DC2
win_dsc:
resource_name: xDnsRecord
Zone: "{{ item.zone }}"
Name: "{{ item.name }}"
Target: "{{ item.target }}"
Type: "{{ item.type }}"
Ensure: "{{ item.state }}"
loop: "{{ dns_nat_dc2_records }}"

when: (env == 'dev' or env == 'stg') and active_site == 'dc2'


What I've observed (whether I'm running either task in the play) is the DNS 
entries aren't present if I specify the state of "absent". If these lines 
are commented out the entries are created (and if running the play multiple 
times and specifying the remote site (e.g dc2 instead of dc1 to trigger the 
dc2 play task) duplicate DNS entries will be created of the hostname 
(different IP as expected).

I've debugged the play and it appears to be looping through in correct 
order - I've read older posts on forums where apparently dictionary's are 
looped in random order (is this still true - I haven't seen it). For 
clarification - the vars I listed above - that is a dictionary with a list 
right? 

Can I loop through the var by first running through the key of "state" and 
value of "absent". I was trying to use dictsort on the loop but couldn't 
get the correct syntax. E.g loop: "{{ dns_nat_dc1_records | 
dictsort(false,'absent') }}"

Have I missed anything obvious?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/19398950-3814-4a07-8435-a6b9fc49e56d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to