I'm having to make multiple changes to my network in a relatively short space of time so to save time I decided to use Ansible.

I have multiple types servers in multiple environments so need to iterate across each environment and each type of server and set the new IP, subnet etc.

For example in ENV1 I might have Web & DB for example with ENV1 on 192.168.64 and Web is .10 and DB is .20 .

So using Ansible and defining two lists and using these in a nested loop, I'd expect to be able to do this based on the environment and type of server.

I could use a command line variable and set the environments subnet for each one but if I can avoid that, I'd like to.

Playbook.

```
---
- hosts: web:db
  become: yes
  vars_files: 
    - vars/network-vars.yaml
  tasks:
    - name: Update the ifcfg-eth0 file
      template:
        src: templates/ifcfg-template.yaml
        dest: /etc/sysconfig/network-scripts/ifcfg-eth0.new
        owner: root
        group: root
        mode: 0644

      when: item.type in group_names and item.env in group_names
      with_items: 
          - "{{ ips }}"
          - "{{ subnets }}"

```

Vars file:

```
---
- netmask: 255.255.255.0
- network: 192.168.64
- dns1: 192.168.64.254
- search: lab.int

- subnets:
    - { env: "env1", net: "192.168.64.2" }

- ips:
    - { type: "web", ip: "10" }
    - { type: "db", ip: "20" }

```

> 
> FAILED! => {"msg": "The conditional check 'item.type in group\_names and '{{env}}' in group\_names' failed. The error was: error while evaluating conditional (item.type in group\_names and '{{env}}' in group\_names): 'env' is undefined
> 
> 
> 

I've tried with\_nested but get a similar error. I've pretty much exhausted reading the man pages and searching for a solution, hence why I'm here. 

TIA.