Hi Nathan.

 

> Ultimately this lens is going to be used from Puppet (…)

That does actually ease the questions as to "is there a match for xyz?" a lot, 
thanks to the onlyif parameter of the Puppet build-in augeas resource. Also, 
you don't need to repeat the full path for your changes constantly, since 
Puppet will append it for you to relative paths.

 

> This is the part which is tripping me up. I can't figure out which fields are 
> available for query of a node (…)

Your link to the Augeas lens isn't working anymore, so I cannot take a look at 
it. However, from your later examples I don't see a problem so far. If you are 
looking for your 'tags' node, which must exist in a specific place, then 
matching for that path is just the right thing!

 

> "If my new tag 'foo:bar' is not already at 
> /files/etc/dd-agent/datadog.conf/Main/tags then go ahead and append it."

You can check whether your tag is listed among the tags (in Puppet) like this:

 

onlyif => 'match Main/tags not_include "foo:bar"'

 

Though appending can become difficult, depending on how the Augeas tree looks 
like. If the value to your tags node is one long string, I don't know a way of 
doing it. If the tags are individual subnodes to the 'tags' tree node, then its 
quite easy.

 

changes => 'set Main/tags/foo bar'

 

Ciao,

Xavier.

 

From: Nathan Valentine [mailto:nrva...@gmail.com] 
Sent: Monday, March 07, 2016 8:43 PM
To: Mol, Xavier (SCC)
Cc: augeas-devel@redhat.com
Subject: Re: [augeas-devel] lens and query to append to a key:value pair in an 
INI file

 

Hey, Xavier.

 

Thanks for the follow-up.

 

 

> 1) creating 'tags' if not present

set $datadog/tags

… will create a 'tags' node (in last position) on root level if it doesn't 
exist yet, otherwise nothing will happen. ($datadog contains the path to your 
datadog.ini file)

 

 

Ultimately this lens is going to be used from Puppet and my 'tag' key should 
*always* exist as /<file>/Main/tags so it seems to make sense to handle that 
end of things with the tools which Puppet provides even if I were not able to 
figure it out at the augeas level.

 

  

> 2) checking the tag string for the presence of my key:value pair

Use 'print' or 'match' with a suitable xpath expression.

 

 

This is the part which is tripping me up. I can't figure out which fields are 
available for query of a node when a lens is based off ot the INIFile lens. For 
instance, this makes sense for /etc/hosts because I have 'ipaddr' and 
'canonical':

 

```

augtool> print /files/etc/hosts

/files/etc/hosts

/files/etc/hosts/1

/files/etc/hosts/1/ipaddr = "127.0.0.1"

/files/etc/hosts/1/canonical = "localhost"

...

augtool> match  /files/etc/hosts/*/ipaddr[../canonical = "localhost"]

/files/etc/hosts/1/ipaddr = 127.0.0.1

```

 

Translating to English, "I'd like the value of the 'ipaddr' field for all 
entries for which the 'canonical' field is 'localhost'.

 

Trying to do something similar for an INIFile based filed...I can't figure out 
what my fields might be for a match so I'm left with an explicit path only to 
get to the 'tag' data:

 

```

augtool> print /files/etc/dd-agent/datadog.conf

...

/files/etc/dd-agent/datadog.conf/Main/#comment[132] = "connection will be 
attempted"

/files/etc/dd-agent/datadog.conf/Main/log_to_syslog = "yes"

/files/etc/dd-agent/datadog.conf/Main/#comment[133] = "syslog_host:"

/files/etc/dd-agent/datadog.conf/Main/#comment[134] = "syslog_port:"

/files/etc/dd-agent/datadog.conf/Main/augeas_key = "canary_value"

/files/etc/dd-agent/datadog.conf/Main/#comment[135] = "augeas comment"

augtool> print /files/etc/dd-agent/datadog.conf/Main/tags

/files/etc/dd-agent/datadog.conf/Main/tags = "owner:nrvale0, 
interactive_users:nrvale0"

 

augtool> match /files/etc/dd-agent/datadog.conf/*/

/files/etc/dd-agent/datadog.conf/#comment = MANAGED BY PUPPET

/files/etc/dd-agent/datadog.conf/Main = (none)

 

augtool> 

```

 

In the end I guess the explicit path to the data is ok (maybe the intent of 
INIFile is such that complicated queries are not that important?) but I'm then 
not certain how, from within Puppet or within augeas, to say:

 

"If my new tag 'foo:bar' is not already at 
/files/etc/dd-agent/datadog.conf/Main/tags then go ahead and append it. Puppet 
doesn't provide a great way to query a resource's value, check it + possibly 
alter it, and then reapply it so I'm hoping there is XPATH syntax to do it. In 
the example above there the desired result would look like so:

 

/etc/etc/dd-agent/datadog.conf/Main/tags = "owner:nrvale0, 
interactive_users,:nrvale0, foo:bar"

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
augeas-devel mailing list
augeas-devel@redhat.com
https://www.redhat.com/mailman/listinfo/augeas-devel

Reply via email to