On Friday, 26 January 2018 17.43.12 CET John Harmon wrote:
>
> On Friday, January 26, 2018 at 12:34:49 AM UTC-7, Kai Stian Olstad wrote:
> >
> > So try this
> >
> > - name: Add DNS entries to ifcfg-* files if missing
> > lineinfile:
> > path: "{{ net_path }}{{ item[0] }}"
> > state: present
> > regexp: "^{{ item[1] }}"
> > line: "{{ item[1] }}={{ vars[item[1] | lower] }}"
> > with_nested:
> > - '{{ ifcfg_list.stdout_lines }}'
> > - [ 'DNS1', 'DNS2' ]
> >
> >
> >
>
> Kai, thank you. That is awesome. I wouldn't have thought of that. I do
> have some follow-up questions, just to understand.
I'll try to explain.
> line: "{{ item[1] }}={{ vars[item[1] | lower] }}"
> What does the = sign do here? Is it overriding the with_nested item[1]?
The = sign is just the = sign.
In the first iteration the "item[1] = DNS1".
You need you the line in the file to be DNS1=10.1.1.10
So {{ item[0] }} would be replaced by the content, so it becomes DNS1, we need
the character = to get DNS=
> What is vars specifying? If I came close to ever doing this on my own I
> wouldn't have added vars.... so I am curious.
Your DNS IP is in the variable named dns, to use the content of a variable as a
variable name you need to use vars or hostvars.
vars if the same as hostvars[inventory_hostname].
item[1] is DNS (upper case) but the variable name is dns (lower case) so
"vars[item[1] | lower]" becomes vars['dns'] that is the same {{ dns }} and you
get 10.1.1.10.
> I know what the rest of it is doing, but am a little fuzzy in regards to
> the two things above.
Hopefully my explanation is understandable.
--
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 [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/28099426.9XW1eVTkh0%40x1.
For more options, visit https://groups.google.com/d/optout.