Ten minutes to set up and ten hours to convince Ansible to not be quite so retarded. The list2dict filter seems to be the (or another) missing piece. Now let’s rewrite everything else using it. Or not.
		
			
				
	
	
		
			28 lines
		
	
	
	
		
			868 B
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
	
		
			868 B
		
	
	
	
		
			YAML
		
	
	
	
	
	
| # TODO rewrite task and templates into something sane once the old DHCP server is retired
 | |
| - set_fact:
 | |
|     dhcp_servers: '{{ prefixes | selectattr("custom_fields.dhcp_server") | groupby(attribute="custom_fields.dhcp_server.address") }}'
 | |
| 
 | |
| - name: Install keepalived
 | |
|   import_tasks: keepalived.yml
 | |
| 
 | |
| - name: Configure DHCP relays
 | |
|   template:
 | |
|     dest: '/etc/default/isc-dhcp-relay-{{ prefixes | selectattr("prefix", "==", item.0 | ipaddr("network/prefix")) | map(attribute="vrf.name") | first }}'
 | |
|     src: isc-dhcp-relay.j2
 | |
|   loop: '{{ dhcp_servers }}'
 | |
|   loop_control:
 | |
|     label: "{{ item.0 }}"
 | |
|   notify: restart keepalived
 | |
| 
 | |
| - name: Set up keepalived
 | |
|   template:
 | |
|     dest: /etc/keepalived/keepalived.conf
 | |
|     src: keepalived.conf.j2
 | |
|     mode: 0600
 | |
|   notify: restart keepalived
 | |
| 
 | |
| - name: Enable keepalived
 | |
|   service:
 | |
|     name: keepalived
 | |
|     enabled: yes
 | |
|     state: started
 |