[augeas-devel] lens and query to append to a key:value pair in an INI file

Nathan Valentine nrvale0 at gmail.com
Mon Mar 7 19:43:22 UTC 2016


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"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20160307/02727075/attachment.htm>


More information about the augeas-devel mailing list