Stephen Sollar
2013-Jan-20 17:53 UTC
[Puppet Users] How do I add multiple new services to /etc/services using augeas/augtool?
I am trying to add multiple new services to /etc/services file. I was able to get one entry placed as the last service, but have been unable to insert additional entries. augtool> set /files/etc/services/service-name[last()] "DB2_db2inst1_1" augtool> set /files/etc/services/service-name[. = ''DB2_db2inst1_1'']/port 60001 augtool> set /files/etc/services/service-name[. = ''DB2_db2inst1_1'']/protocol tcp augtool> save Saved 1 file(s) cat /etc/services | grep DB_db2inst1_1 DB2_db2inst1_1 60001/tcp I tried using the service-name[last()+1] to add a service after that last one but it errors and will not save using augtool. set /files/etc/services/service-name[last()+1] "DB2_db2inst1_2" set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/port 60002" set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/protocol tcp" I would like the output to look like this; DB2_db2inst1_1 60001/tcp DB2_db2inst1_2 60002/tcp Im sure there is a way with Xpath to write to the next line, but I have not been successful with it yet. Any thoughts? -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/uezInlCritIJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Dominic Cleal
2013-Jan-21 08:00 UTC
Re: [Puppet Users] How do I add multiple new services to /etc/services using augeas/augtool?
On 20/01/13 17:53, Stephen Sollar wrote:> I am trying to add multiple new services to /etc/services file. I was > able to get one entry placed as the last service, but have been unable > to insert additional entries. > > augtool> set /files/etc/services/service-name[last()] "DB2_db2inst1_1"last() in this case is going to overwrite the last entry you already have in the file, you want to use last()+1 instead.> augtool> set /files/etc/services/service-name[. = ''DB2_db2inst1_1'']/port > 60001 > augtool> set /files/etc/services/service-name[. > ''DB2_db2inst1_1'']/protocol tcp > augtool> save > Saved 1 file(s) > > cat /etc/services | grep DB_db2inst1_1 > DB2_db2inst1_1 60001/tcp > > I tried using the service-name[last()+1] to add a service after that > last one but it errors and will not save using augtool. > > set /files/etc/services/service-name[last()+1] "DB2_db2inst1_2" > set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/port 60002" > set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/protocol tcp"There''s a trailing quote on these two lines.> I would like the output to look like this; > DB2_db2inst1_1 60001/tcp > DB2_db2inst1_2 60002/tcp > > Im sure there is a way with Xpath to write to the next line, but I have > not been successful with it yet. Any thoughts?The example here works fine for me. You say it errors - what error does it give? You might need to run "print /augeas//error" to get detailed output. If you''re using Puppet 3, --debug gives the same information. A slightly better way than using last()+1 is to do this, which has the bonus of being entirely idempotent - so if the line already exists, it won''t add a second. set /files/etc/services/service-name[. = ''DB2_db2inst1_2''] "DB2_db2inst1_2" set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/port 60002 set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/protocol tcp -- Dominic Cleal Red Hat Engineering -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Stephen Sollar
2013-Jan-22 23:16 UTC
[Puppet Users] Re: How do I add multiple new services to /etc/services using augeas/augtool?
I got it to work, I just had to give it all of the configurations (port, protocol, comment) then save. set /files/etc/services/service-name[last()+1] "DB2_db2inst1_2" set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/port 60002 set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/protocol tcp set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']#comment "hello" save On Jan 21, 3:00 am, Dominic Cleal <dcl...@redhat.com> wrote:> On 20/01/13 17:53, Stephen Sollar wrote: > > > I am trying to add multiple new services to /etc/servicesfile. I was > > able to get one entry placed as the last service, but have been unable > > to insert additional entries. > > > augtool> set /files/etc/services/service-name[last()] "DB2_db2inst1_1" > > last() in this case is going to overwrite the last entry you already > have in the file, you want to use last()+1 instead. > > > > > > > > > > > augtool> set /files/etc/services/service-name[. = ''DB2_db2inst1_1'']/port > > 60001 > > augtool> set /files/etc/services/service-name[. > > ''DB2_db2inst1_1'']/protocol tcp > > augtool> save > > Saved 1 file(s) > > > cat /etc/services| grep DB_db2inst1_1 > > DB2_db2inst1_1 60001/tcp > > > I tried using the service-name[last()+1] to add a service after that > > last one but it errors and will not save using augtool. > > > set /files/etc/services/service-name[last()+1] "DB2_db2inst1_2" > > set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/port 60002" > > set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/protocol tcp" > > There''s a trailing quote on these two lines. > > > I would like the output to look like this; > > DB2_db2inst1_1 60001/tcp > > DB2_db2inst1_2 60002/tcp > > > Im sure there is a way with Xpath to write to the next line, but I have > > not been successful with it yet. Any thoughts? > > The example here works fine for me. You say it errors - what error does > it give? You might need to run "print /augeas//error" to get detailed > output. If you''re using Puppet 3, --debug gives the same information. > > A slightly better way than using last()+1 is to do this, which has the > bonus of being entirely idempotent - so if the line already exists, it > won''t add a second. > > set /files/etc/services/service-name[. = ''DB2_db2inst1_2''] "DB2_db2inst1_2" > set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/port 60002 > set /files/etc/services/service-name[. = ''DB2_db2inst1_2'']/protocol tcp > > -- > Dominic Cleal > Red Hat Engineering-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.