On Sat, Jan 19, 2019 at 11:04 AM <[email protected]> wrote: > > My Requirement is as follows > > Below is the list of variables and its multiple values : > > host1 > env : qa,dev,uat > grpn: g1 > type: t1 > port: 1401 > type: t2 > port: 1402 > type: t3 > port: 1403 > > host2 > env : qa,dev,uat > grpn: g21 > type: t1 > port: 1605 > type: t2 > port: 1606 > > host3 > env : qa,dev,uat > grpn: g1 > type: t1 > port: 1503 > type: t2 > port: 1504 > > etc and the list goes on for many hosts(more than 100 hosts and each host has > min 3 applications at 3 diff ports) > > I need to do application deployment based on above concept: > i,e host1 belongs to g1 and one application will be of type1(t1) running > under port 1401 and another application of type t2 running at port 1402. I > also need to capture the groupname(g1,g2,g2 etc) for every application. > > Thus for each host there is a dictionary of type and port, For each type , > the port is different. > > The above list is huge and its difficult to write so many stanzas in yml > format in vars_file. So I thought I'll use host_variables in inventory like > below after placing the hosts in different environments under the inventory. > > host1 grpn: g1 port: [1401,1401,1403] type: [t1, t2, t3] > host2 grpn: g2 port: [1605,1606] type: [t1, t2] > > > My expectation is that for each host it should pick the groupname(grpn) and > also for type 1 it should pick port1 and for type2 it should pick port2 and > deploy the application respectively.. > > But Im not aware how to read the variables from the inventory and how to > ensure the type - port pair is maintained while deployment. > > I thought I'll create a jinja2 template like below but Im still confused how > to achieve the type and port match. > > test.yml.j2 > > --- > deploy: > - host: host1 > portnum : {{ port }} > groupname: {{ grpn }} > type: {{ type }} > env : {{ env }} > > Kindly suggest how I can achieve this?? > Have you searched previous posts in the mailing list? Have you read the loop examples in the ansible docs?
> -- > 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/a63c9aa4-fd0b-41ce-ad5a-3ddda6a49c0e%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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/CAHEKYV5scweU5MSmC61jmH3fA_NGHEtUsxMLHnao49MPg6HjrQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
