HI Kai Stian Olstad ,

That helped me and thanks a ton but that scenario works better if we know 
the number of docker networks. 
Here is the exact use case where I need to generate multiple docker network 
files based on the number of container count and push a single template 
multiple times to match the container count updating the correct network 
details. I would get docker1ip/nm/gw docker2ip/nm/gw dockernip/nm/gw from 
external source and just for testing i mentioned them as vars in this 
playbook.


- name: Get number of Containers (Number of logical drives excluding the OS)
  shell: echo `/sbin/hpssacli ctrl all show config | grep logical | wc -l` -1 | 
bc
  register: container_count


 - name: Generating docker network Files
    template: src=templates/docker_interface 
dest=/etc/sysconfig/network-scripts/ifcfg-docker{{ item }}
    vars:
      ipaddress: {{ docker{{ item }}ip }}
      netmask: {{ docker{{ item }}nm }}
      gateway: {{ docker{{ item }}gw }}
    with_sequence: start=1 end={{ container_count.stdout }} stride=1


template

DEVICE=docker{{ item }}
BONDING_OPTS="miimon=100 mode=1"
ONPARENT=yes
BOOTPROTO=static
IPADDR={{ ipaddress }}
NETMASK={{ netmask }}
GATEWAY={{ gateway }}

Can you help me with this one

On Wednesday, April 26, 2017 at 12:15:13 AM UTC-7, Kai Stian Olstad wrote:
>
> On 26.04.2017 01:19, Kiran Kumar wrote: 
> > Am having a challenge finding a solution to below issue. 
> > I need to generate multiple network files based on single template and 
> > the 
> > value of template should change based on the item like IP/NM/GW . 
> > 
> > Example 
> > 
> > vars: 
> >   docker1ip: 1.2.3.4 
> >   docker1nm: 255.255.255.1 
> >   docker1gw: 1.2.3.1 
> >   docker2ip: 1.2.3.5 
> >   docker2nm: 255.255.255.2 
> >   docker2gw: 1.2.3.1 
> > 
> > 
> >   - name: Generating docker network Files 
> >     template: src=templates/docker_interface 
> > dest=/etc/sysconfig/network-scripts/ifcfg-docker{{ item }} 
> >     vars: 
> >       ipaddress: {{ docker{{ item }}ip }} 
> >       netmask: {{ docker{{ item }}nm }} 
> >       gateway: {{ docker{{ item }}gw }} 
> >     with_sequence: start=1 end=2 stride=1 
>
> Variables in variables is not possible like this, you need to do it like 
> this 
>
> https://docs.ansible.com/ansible/faq.html#when-should-i-use-also-how-to-interpolate-variables-or-dynamic-variable-names
>  
>
>
> > template 
> > 
> > DEVICE=docker{{ item }} 
> > BONDING_OPTS="miimon=100 mode=1" 
> > ONPARENT=yes 
> > BOOTPROTO=static 
> > IPADDR={{ ipaddress }} 
> > NETMASK={{ netmask }} 
> > GATEWAY={{ gateway }} 
> > 
> > 
> > Above task doesnt work but I need a solution it may be a different 
> > approach 
> > too. 
>
> Since you are specifying everything why not restructure the variable, 
> one example on how to do it: 
>
> vars: 
>    docker_inv: 
>      - host: docker1 
>        ip: 1.2.3.4 
>        nm: 255.255.255.1 
>        gw: 1.2.3.1 
>      - host: docker2 
>        ip: 1.2.3.5 
>        nm: 255.255.255.2 
>        gw: 1.2.3.1 
>
>    - name: Generating docker network Files 
>      template: src=templates/docker_interface 
> dest=/etc/sysconfig/network-scripts/ifcfg-{{ item.host }} 
>      with_items: '{{ docker_inv }}' 
>
> template 
> -------- 
> DEVICE={{ item.host }} 
> BONDING_OPTS="miimon=100 mode=1" 
> ONPARENT=yes 
> BOOTPROTO=static 
> IPADDR={{ item.ip }} 
> NETMASK={{ item.nm }} 
> GATEWAY={{ item.gw }} 
>
> -- 
> Kai Stian Olstad 
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2db376d5-198c-4029-bb3e-914df8e5f601%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to