Can I use an operator with onlyif using augeas

asked 2017-04-27 06:24:31 -0500

monalsharma gravatar image

I am looking to do something like this:

augeas{'update loopback in hosts file': context => "/files${hostsfile}", onlyif => "match /files/etc/hosts/1/ipaddr[.='127.0.0.1'] size == 0" or "match /files/etc/hosts/1/alias[2][.= 'localhost4'] size == 1" or "match /files/etc/hosts/1/alias[3][.= 'localhost4.localdomain'] size == 1",

Use Case:

If the first line of the /etc/hosts file DOES NOT have ipaddr = 127.0.0.1 OR If the first line of the /etc/hosts file HAS alias[2] = localhost4 AND alias [3] = localhost4.localdomain

In simple words, I want the first line of the /etc/hosts to look like this:

127.0.0.1 localhost localhost.localdomain 10.10.10.10 abchost01 abchost01.xyz.com

If you can suggest a better way to do this, please advise. Thanks

edit retag flag offensive close merge delete

Comments

sorry about the auto-correct, the file should look like this: 127.0.0.1 localhost localhost.localdomain 10.10.10.10 abchost01 abchost01.xyz.com

monalsharma gravatar imagemonalsharma ( 2017-04-27 09:00:23 -0500 )edit