title: Ansible loop over variables
body: <p>i am using ansible to update configuration file of newly added NIC
  for that i have  defined some variables in separate yml file </p>
  
  <p><strong>/tmp/ip.yml</strong></p>
  
  <pre><code>#first interface
  interface1: eth1
  bootproto1: static
  ipaddress1: 192.168.211.249
  netmask1: 255.255.255.0
  gateway: 192.168.211.2
  DNS1: 192.168.211.2
  
  #second interface
  interface2: eth2
  bootproto2: static
  ipaddress2: 10.0.0.100
  netmask2: 255.0.0.0
  </code></pre>
  
  <p><strong>Playbook</strong></p>
  
  <pre><code>- include_vars: /tmp/ip.yml
  
  - name: configuring interface 
    lineinfile:
      state=present
      create=yes
      dest=/etc/sysconfig/network-scripts/ifcfg-{{interface1}}
      regexp="{{ item.regexp }}"
      line="{{ item.line }}"
    with_items:
       - { regexp: '^BOOTPROTO=.*', line: 'BOOTPROTO={{interface1}}' }
       - { regexp: '^IPADDR=.*', line: 'IPADDR={{ipaddress1}' }
       - { regexp: '^NETMASK=.*', line: 'NETMASK={{netmask1}}' }
       - { regexp: '^GATEWAY=.*', line: 'GATEWAY={{gateway}}' }
       - { regexp: '^PEERDNS=.*', line: 'PEERDNS=no' }
       - { regexp: '^DNS1=.*', line: 'DNS1={{DNS1}}' }
       - { regexp: '^ONBOOT=.*', line: 'ONBOOT={{onboot}}' }
  when: bootproto1 == 'static'
  
  - name: configuring for DHCP
    lineinfile:
     state=present
     create=yes
     dest=/etc/sysconfig/network-scripts/ifcfg-{{interface1}}
     regexp="{{ item.regexp }}"
     line="{{ item.line }}"
    with_items:
      - { regexp: '^BOOTPROTO=.*',line: 'BOOTPROTO={{bootproto1}}' }
      - {regexp: '^PEERDNS=.*',line: 'PEERDNS=yes' }
      - { regexp: '^ONBOOT=.*', line: 'ONBOOT={{onboot}}' }
  when: bootproto1 == 'dhcp'
  </code></pre>
  
  <p>similarly repeated for second interface.</p>
  
  <p>Even Though this method works for 2 NIC,this is too difficult to manage ,that is for each new NIC added i need to modify playbook and update corresponding variable in <strong>/tmp/ip.yml</strong>.</p>
  
  <p>Is there a way to add variables to /tmp/ip.yml and may be using some separator parse it to playbook with out modifying playbook each time for plugging in new NIC.</p>