Ask Your Question
0

issue with augeas in services file

asked 2015-03-05 11:50:39 -0500

Chutki gravatar image

HI,

I am testing below manifests for /etc/services

define services::ifx_services($id,$value){  
require services::services_icl
  augeas {$value:
    lens    => 'services.lns',
    incl    => '/etc/services',
    changes => ["insert service-name after service-name[last()]",
                "set service-name[last()] test$id",
                "set service-name[.='test$id']/port $value",
                "set service-name[.='test$id']/protocol tcp",
                "insert service-name after service-name[last()]",
                "set service-name[last()] test$id",
                "set service-name[.='test$id'][2]/port $value",
                "set service-name[.='test$id'][2]/protocol udp"],
     onlyif  => "match service-name[service-name = 'test$id'][port = '$value'] size == 0"
   }
}

When I run first time all services what I updated in hieara, the value is getting inserted.

Notice: /Stage[main]/Services/Services::Ifx_services[service84]/Augeas[084]/returns: executed successfully
Notice: Augeas[085](provider=augeas):
--- /etc/services       2015-03-05 06:10:45.892212493 -0500
+++ /etc/services.augnew        2015-03-05 06:10:47.338215800 -0500
@@ -10942,3 +10942,5 @@
test83 5083/udp
test84 5084/tcp
test84 5084/udp
+test85 5085/tcp
+test85 5085/udp



Notice: /Stage[main]/Services/Services::Ifx_services[service85]/Augeas[085]/returns: executed successfully
Notice: Augeas[086](provider=augeas):
--- /etc/services       2015-03-05 06:10:48.890219352 -0500
+++ /etc/services.augnew        2015-03-05 06:10:50.371222738 -0500
@@ -10944,3 +10944,5 @@
test84 5084/udp
test85 5085/tcp
test85 5085/udp
+test86 5086/tcp
+test86 5086/udp



Notice: /Stage[main]/Services/Services::Ifx_services[service86]/Augeas[086]/returns: executed successfully 
test0 5000/tcp
test0 5000/udp
test1 5001/tcp

but when I run second time I get below error

Debug: Augeas[000](provider=augeas): Opening augeas with root /, lens path , flags 64
Debug: Augeas[000](provider=augeas): Augeas version 1.1.0 is installed
Debug: Augeas[000](provider=augeas): Will attempt to save and only run if files changed
Debug: Augeas[000](provider=augeas): sending command 'insert' with params ["service-name", "after", "/files/etc/services/service-name[last()]"]
Debug: Augeas[000](provider=augeas): sending command 'set' with params ["/files/etc/services/service-name[last()]", "test0"]
Debug: Augeas[000](provider=augeas): sending command 'set' with params ["/files/etc/services/service-name[.='test0']/port", "5000"]
Debug: Augeas[000](provider=augeas): sending command 'set' with params ["/files/etc/services/service-name[.='test0']/protocol", "tcp"]
Debug: Augeas[000](provider=augeas): sending command 'insert' with params ["service-name", "after", "/files/etc/services/service-name[last()]"]
Debug: Augeas[000](provider=augeas): sending command 'set' with params ["/files/etc/services/service-name[last()]", "test0"]
Debug: Augeas[000](provider=augeas): sending command 'set' with params ["/files/etc/services/service-name[.='test0'][2]/port", "5000"]
Debug: Augeas[000](provider=augeas): sending command 'set' with params ["/files/etc/services/service-name[.='test0'][2]/protocol", "udp"]
Debug: Augeas[000](provider=augeas): Put failed on one or more files, output from /augeas//error:
Debug: Augeas[000](provider=augeas): /augeas/files/etc/services/error = put_failed
Debug: Augeas[000](provider=augeas): /augeas/files/etc/services/error/path = /files/etc/services/service-name
Debug: Augeas[000](provider=augeas): /augeas/files/etc/services/error/lens = /opt/puppet/share/augeas/lenses/dist/services.aug:80.15-83.33:
Debug: Augeas[000](provider=augeas): /augeas/files/etc/services/error/message = Failed to match
    ({ /port/ = /[0-9]+/ } | { /start/ = /[0-9]+/ }{ /end/ = /[0-9]+/ }){ /protocol/ = /[A-Za-z]+/ }({ /alias/ = /[*+.-9A-Z_a-z- ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-03-05 16:37:04 -0500

GregLarkin gravatar image

Absolutely have a look at this module on the Puppet Forge to manage /etc/services entries: https://forge.puppetlabs.com/ccin2p3/etc_services

Even if you decide not to use it, it uses augeas to manage entries, so you may be able to pick up some techniques for your use. However, it's probably better to try using it and adding more features to it as needed while also submitting pull requests back to the author for inclusion.

edit flag offensive delete link more

Comments

Thanks Greg, but is it not possible to rework augeas to fix the error what I posted

Chutki gravatar imageChutki ( 2015-03-08 17:45:11 -0500 )edit

It might be, but why would you? If you would like to manually write your own augeas code, follow my previous suggestion of at least looking at how the ccin2p3/etc_services module does it. You can probably find what you need in there. However, the less you reinvent the wheel, the better.

GregLarkin gravatar imageGregLarkin ( 2015-03-09 16:13:43 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-03-05 11:50:39 -0500

Seen: 342 times

Last updated: Mar 05 '15