Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  ℝaphink Jun 20 '12 at 22:26

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Perfect, thanks. The 'ins' syntax looked like what should be in use but it reliably bombed out. –  Tim Brigham Jun 20 '12 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. –  ℝaphink Jun 20 '12 at 22:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.