I'm no expert, but I've messed with Augeas a bit and you can make it harder than it needs to be without even trying. I haven't done anything in `/etc/services`, but I had a similar issue with `sudoers`. A trick to keep in mind is that if you set something on a path that doesn't exist, Augeas will create it. So, if you can find something that makes an item unique, you can use that to specify a path. In this case, the port number will probably work.
augeas { 'app_tcp':
context => '/files/etc/services',
changes => [
"set /files/etc/services/service-name[port = '1002']/port 1002"
"set /files/etc/services/service-name[port = '1002'] app_tcp"
"set /files/etc/services/service-name[port = '1002']/protocol tcp"
"set /files/etc/services/service-name[port = '1002']/#comment foo"
],
}
This should create the line in `/etc/services` if it doesn't exist, but if it does exist and nothing has changed, Puppet won't do anything to the line (which is generally what you want). Setting the “name” doesn't seem to work until after the thing exists, which is why it appears second on the list.
--
Rob McBroom
<http://www.skurfer.com/>
It's not that I think guns, drugs, prostitution, swimming, eating and reading should be legal. It's just that no one on Earth has the authority to make them illegal.
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
> # puppet -ddd foo1.pp
> Could not parse for environment production: Syntax error at 'set /files/etc/services/service-name[port = '1002'] app_tcp'; expected ']' at /data/foo1.pp:5
It looks like you're trying to use single-quotes (for the port number) inside of single-quotes (for the entire set statement). You'll have to use double-quotes in one place or the other, or escaping the inner single-quotes might also work.
I tested it using `augtool`, so it works. It's just a matter of translating it and quoting it correctly for Puppet.
> Now if I single quote the port number in the [] I get another error.. which likely means using the '' is not correct.
>
> err: //Augeas[cti-p01-dgw_tcp]/returns: change from need_to_run to 0 failed: Save failed with return code false
Ah, then I suspect you're using 0.24.x.
http://projects.reductivelabs.com/issues/2141
I wouldn't even bother with Augeas until you go to 0.25.x where this bug was fixed.
My original example was missing commas after the various set statements. Not sure if you fixed that. It also specified the full path, even though the context should have taken care of most of it. That didn't seem to hurt, but to be safe, I took it out. I'm also using 0.25.4 and this worked:
augeas { 'app_tcp':
context => '/files/etc/services',
changes => [
"set service-name[port = '1002']/port 1002",
"set service-name[port = '1002'] app_tcp",
"set service-name[port = '1002']/protocol tcp",
# "set service-name[port = '1002']/#comment foo",
],
}
I disabled the comment because the line ended up looking like this:
app_tcp 1002/tcp# foo
But that's probably a bug in the Agueas lens, not Puppet.
> You know what the problem was, my ordering. I had app_tcp first and not port 1002 so thats likely why it was not getting picked up. Worked, but hit another snag. Now try adding another app name, same port but for udp, it will just get overwritten.
I addressed both of those things in my initial reply.
On the order of `set` statements:
> Setting the “name” doesn't seem to work until after the thing exists, which is why it appears second on the list.
On adding both TCP and UDP entries:
> So, if you can find something that makes an item unique, you can use that to specify a path.
If two entries are using the same port number, that obviously won't work as a unique identifier. You could maybe use a unique comment on each one, but there seems to be that bug where no space appears between protocol and comment. Perhaps there's a way to specify a path using more than one component. A combination of port and protocol should be unique, for example.
> I tried using the "alias" option as an identifier, but have not been succesful with it. I will play that a little bit more as I think that may be the only way to do it that I know of.
It looks like you can use the port/protocol combination. At least it works for printing. I haven't tested it to create a new entry.
augtool> print /files/etc/services/service-name[port = '443'][protocol = 'tcp']
/files/etc/services/service-name[161] = "https"
/files/etc/services/service-name[161]/port = "443"
/files/etc/services/service-name[161]/protocol = "tcp"
/files/etc/services/service-name[161]/#comment = "MCom"
--
Rob McBroom
<http://www.skurfer.com/>
Don't try to tell me something is important to you if the whole of your “support” entails getting Congress to force *others* to spend time and money on it.
/files/etc/services/service-name[port = '443' and protocol = 'tcp']
/files/etc/services/*[port = '443' and protocol = 'tcp']
Maybe you should just take a look at <http://augeas.net/page/Path_expressions>.
--
> What version of augeas are you using? I am on 0.5.3 I don't think support has been added to do some of that functionality I am going to upgrade
0.7.0
> I tested the new version from the CLI, I noticed it is quite different and more powerful features. But I wonder if puppet has caught to support them in the augeas provider. If I set this below it fails and either operation.
Be sure to update augeas-libs and ruby-augeas too. (Those are the names of the packages from EPEL. You may have them under different names.) Puppet doesn't use `augtool`.
servername.<data center>.host-name.net
I'd like to be able to create a single server image with puppet configured
that can work with multiple data centers. Right now, my image is tied to
a single data center, so /etc/resolv.conf looks like this:
nameserver 1.2.3.4
nameserver 1.2.3.5
search iad01.host-name.net
The issue there is if I decide to use this image in a different data
center, which would have its own puppet instance setup.
So just to standardize, what I've been thinking of doing instead is
creating a "fake" data center, where CNAMEs live for other data centers,
such as:
So we'd have:
nameserver 1.2.3.4
nameserver 1.2.3.5
search launch.host-name.net
That way, when puppet searches for "puppet" as a shortname (which it does
by default), it will try to connect to puppet.launch.host-name.net, which
is a central host. After it receives it's appropriate /etc/resolv.conf,
which will include data center specific things in it, I'll have that
puppetmaster instance restart puppet, which will then point it to its
local puppet instance....
Would this work? Assuming the same certificate was on both puppetmaster
servers?
Or is this asking for trouble?
-Matt
Why not use DNS views? In each of your data center puppet resolves to the local
puppetmaster.
--
Mathias Gug
Ubuntu Developer http://www.ubuntu.com