how to get all the details

53 views
Skip to first unread message

coach...@gmail.com

unread,
Nov 28, 2017, 6:15:41 AM11/28/17
to Ansible Project
IS there is a way that we can get the name of all network interfaces as we have ansible_default_ipv4.interface gives only the primary one . Need to get all the interface name so that a parameter can be modified for it.

Kai Stian Olstad

unread,
Nov 28, 2017, 9:31:12 AM11/28/17
to ansible...@googlegroups.com
ansible_interfaces it's list with all of them.

You can always run "ansible host -m setup" to check all the facts from a host.


--
Kai Stian Olstad

coach rhca

unread,
Nov 28, 2017, 9:36:53 AM11/28/17
to ansible...@googlegroups.com
thanks Kai, actually trying to edit a parameter in the network  interface files I am using something like
lineinfile: "dest=/etc/sysconfig/network-scripts/ifcfg-{{ ansible_default_ipv4.interface }} regexp='^{{ item.regexp }}' line='{{
 item.line }}'"

but this only gives me the default network card but i want to edit the changes in all the available network interfaces like ifcfg-en0117 or ifcfg-en037 whatever is present in the host except the lo interface..could you please suggest as to how we can do on multiple interface...thank you .


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Jj4e_dFxiW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@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/1685407.S9aSPNRFpI%40x1.
For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Nov 28, 2017, 9:58:26 AM11/28/17
to ansible...@googlegroups.com
On Tuesday, 28 November 2017 15.36.34 CET coach rhca wrote:
>
> thanks Kai, actually trying to edit a parameter in the network interface
> files I am using something like
> lineinfile: "dest=/etc/sysconfig/network-scripts/*ifcfg-{{
> ansible_default_ipv4.interface }*} regexp='^{{ item.regexp }}' line='{{
> item.line }}'"
>
>
> but this only gives me the default network card but i want to edit the
> changes in all the available network interfaces like ifcfg-en0117 or
> ifcfg-en037 whatever is present in the host except the lo interface..could
> you please suggest as to how we can do on multiple interface...thank you .

I would use the find module to find ifcfg-* in /etc/sysconfig/network-scripts/ and exclude ifcfg-lo.
Register the output in a variable and loop over the entries in the varaible with with_items on lineinfile.


--
Kai Stian Olstad

coach rhca

unread,
Nov 29, 2017, 9:35:17 AM11/29/17
to ansible...@googlegroups.com
Thanks Kai, I did the same as suggested by you to find the ifcfg-* but when i register the variable say result. the output of the result variable shows the entire list of attributes of the file, we need to get only the name of the interface but what the output is as below..could you please suggest as to how to curtail the output to give interface name:

the output shows as below :

 {
                "atime": 1511964673.1590006,
                "ctime": 1511420044.9254873,
                "dev": 2051,
                ..................................
                "isreg": true,
                "issock": false,
                "isuid": false,
                "mode": "0644",
                "mtime": 1511420044.9214873,
                "nlink": 1,
                "path": "/etc/sysconfig/network-scripts/ifcfg-eno16777736",
                "rgrp": true,
                "roth": true,
}


 {
                "atime": 1511964673.1320007,
                "ctime": 1511852951.9169016,
                "dev": 2051,
                "gid": 0,
                "inode": 101194774,
                "isblk": false,
                "issock": false
                 .....................
                "isuid": false,
                "mode": "0644",
                "mtime": 1511852951.9169016,
                "nlink": 1,
                "path": "/etc/sysconfig/network-scripts/ifcfg-Ethernet_connection_1",
                "rgrp": true,
                "roth": true,
                "rusr": true,
}




--
Kai Stian Olstad

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Jj4e_dFxiW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

Kai Stian Olstad

unread,
Nov 29, 2017, 9:44:52 AM11/29/17
to ansible...@googlegroups.com
On Wednesday, 29 November 2017 15.35.03 CET coach rhca wrote:
>
> Thanks Kai, I did the same as suggested by you to find the ifcfg-* but when
> i register the variable say result. the output of the result variable shows
> the entire list of attributes of the file, we need to get only the name of
> the interface but what the output is as below..could you please suggest as
> to how to curtail the output to give interface name:
>
>
> the output shows as below :
>
>
> {
> "atime": 1511964673.1590006,
> "ctime": 1511420044.9254873,
> "dev": 2051,
> ..................................
> "isreg": true,
> "issock": false,
> "isuid": false,
> "mode": "0644",
> "mtime": 1511420044.9214873,
> "nlink": 1,
> "path": "/etc/sysconfig/network-scripts/ifcfg-eno16777736",
> "rgrp": true,
> "roth": true,
> }


- debug: msg="The interface {{ item.path.split('-')[2] }} is configured in {{ item.path }}"
with_items: '{{ result.files }}'


--
Kai Stian Olstad

coach rhca

unread,
Nov 30, 2017, 7:25:09 AM11/30/17
to ansible...@googlegroups.com
Thanks Kai for the help.appreciate it



--
Kai Stian Olstad

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Jj4e_dFxiW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

coach rhca

unread,
Nov 30, 2017, 12:04:37 PM11/30/17
to ansible...@googlegroups.com
Also want to know , here we are using the result.files , what are the other options we can use..could you please suggest any link where we can get more info about the options available we can use just like results.files

On Thu, Nov 30, 2017 at 5:54 PM, coach rhca <coach...@gmail.com> wrote:
Thanks Kai for the help.appreciate it

Kai Stian Olstad

unread,
Nov 30, 2017, 12:10:24 PM11/30/17
to ansible...@googlegroups.com
On Thursday, 30 November 2017 18.04.19 CET coach rhca wrote:
>
> Also want to know , here we are using the result.files , what are the other
> options we can use..could you please suggest any link where we can get more
> info about the options available we can use just like results.files

For the find, it's documented at the bottom of the find module documentation page.
For other modules the dictionary is different, most of them is not documented, so the best you can do is check with debug module.

- debug: var=<varaible_name>


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages