1

I have a config file in augeas using a custom lens that outputs the data as follows.

/files/opt/../server.conf/target[1] = "general"
/files/opt/../server.conf/target[1]/serverName = "XXX"
/files/opt/../server.conf/target[1]/guid = "XXX0XXX"
/files/opt/../server.conf/target[2] = "sslConfig"
/files/opt/../server.conf/target[2]/sslKeysfilePassword  = "$1$XXXXX" 

This works well - some of the target names contain colons, etc so I need to use the target[x] format.

What is the correct ins syntax to create a new section in my INI using this syntax?

1
  • Note that .. is a valid Augeas path syntax, meaning parent node, but it's most likely not what you meant here. To clarify, I used ... in my answer.
    – raphink
    Jun 20, 2012 at 22:26

1 Answer 1

3

You can use:

set /files/opt/.../server.conf/target[. = 'newsection'] 'newsection'

If the section doesn't exist yet, it will create it. You can then use it to add keys under this section. This code is idempotent, so it is safe to use it for every section you need keys for, as it will only create the section if it doesn't exist yet.

For the record, you could use ins if you really wanted your new section to appear before an existing one, for example:

# Add a new target node before the sslConfig target
ins target before /files/opt/.../server.conf/target[. = 'sslConfig']
# Set the target name to "newsection" by matching the node right before the "sslConfig" target
set /files/opt/.../server.conf/target[following-sibling::*[1][label() = 'target'][. = 'sslConfig']] 'newsection'

Note that the code above is not idempotent, unlike the first code I pasted. If you use Augeas with Puppet, you would probably want to add an onlyif statement to apply such changes in an idempotent way.

2
  • Perfect, thanks. The 'ins' syntax looked like what should be in use but it reliably bombed out. Jun 20, 2012 at 16:11
  • You could use the ins syntax if you really wanted your new section to appear before a given existing section, but that would make things more complex.
    – raphink
    Jun 20, 2012 at 22:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .