[Puppet Users] ldap node attributes containing dash ( - )

139 views
Skip to first unread message

donavan

unread,
May 6, 2010, 7:31:59 PM5/6/10
to Puppet Users
Am I missing some clever way to use variables containing a dash in the
name?

We're using LDAP nodes I may have a node like this example:

dn: cn=ns01.domain.com,cn=machines,o=domain
cn: ns01.domain.com
objectClass: top
objectClass: puppetClient
ipHostNumber: 192.201.112.90
parentnode: basenode-without-autofs
puppetclass: default_access
console-port: 7025@cyclada4

And I'd like to access 'console-port' as a variable in a manifest. In
ruby land I end up resorting to stupid tricks like
instance_variable_get('@console-port') or ['console-port'] to get
this.

Any suggestions besides a hackier implementation of get_var() function?

--
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.

Trevor Vaughan

unread,
May 6, 2010, 8:46:50 PM5/6/10
to puppet...@googlegroups.com, donavan
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I don't think that ruby itself allows variables with dashes in the name
since it will probably interpret them as minus signs and try to
interpret the variables around the symbol.

Trevor

On 05/06/2010 07:31 PM, donavan wrote:
> Am I missing some clever way to use variables containing a dash in the
> name?
>
> We're using LDAP nodes I may have a node like this example:
>
> dn: cn=ns01.domain.com,cn=machines,o=domain
> cn: ns01.domain.com
> objectClass: top
> objectClass: puppetClient
> ipHostNumber: 192.201.112.90
> parentnode: basenode-without-autofs
> puppetclass: default_access
> console-port: 7025@cyclada4
>
> And I'd like to access 'console-port' as a variable in a manifest. In
> ruby land I end up resorting to stupid tricks like
> instance_variable_get('@console-port') or ['console-port'] to get
> this.
>
> Any suggestions besides a hackier implementation of get_var() function?
>

- --
Trevor Vaughan
Vice President, Onyx Point, Inc.
email: tvau...@onyxpoint.com
phone: 410-541-ONYX (6699)
pgp: 0x6C701E94

- -- This account not approved for unencrypted sensitive information --
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkvjYvoACgkQyWMIJmxwHpTm9ACeO7bvFMVPYLaIRi9mOjZvPOPA
TYAAn03GCbYaC+5kr/AogVsJ7o12dNLd
=aaay
-----END PGP SIGNATURE-----
tvaughan.vcf

donavan

unread,
May 7, 2010, 1:44:42 PM5/7/10
to Puppet Users
On May 6, 5:46 pm, Trevor Vaughan <tvaug...@onyxpoint.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I don't think that ruby itself allows variables with dashes in the name
> since it will probably interpret them as minus signs and try to
> interpret the variables around the symbol.

Right. Which is why, in ActiveLdap for example, I would have to use a
string with the hash access method:

>> ns01.cn
=> "ns01.domain.com"
>> ns01.dns-ns
NoMethodError: undefined method `dns' for #<Machine:0x240ea28>
>> ns01["cn"]
=> "ns01.domain.com"
>> ns01["dns-ns"]
=> "10041801"

And in other cases I could use the instance_variable_get method to
pull it out:

>> ns01.instance_variable_get("@data")["dns-ns"]
=> ["10041801"]

But I don't have either of those from a manifest. So I can
trysomething like get_var[1]. I was just hoping someone out there had
a cleaner work around for me.

[1] http://projects.puppetlabs.com/projects/puppet/wiki/Ldap_Nodes

donavan

unread,
May 7, 2010, 1:54:18 PM5/7/10
to Puppet Users
On May 6, 4:31 pm, donavan <dona...@desinc.net> wrote:
> Am I missing some clever way to use variables containing a dash in the
> name?
>
> We're using LDAP nodes I may have a node like this example:
..
> And I'd like to access 'console-port' as a variable in a manifest.

Reading over I realize this may not be clear to people not using
LdapNodes[1]. "All attributes on the LDAP nodes are assigned as
variables in the Puppet configuration". This gives you puppet
variables like $ipHostNumber for free.

I have an LDAP attribute I need to check from inside my manifest. The
issue is the attribute name contains a dash. So I can't use the
regular semantics of $<attribute name> to access it. Any way to get
this attribute without a hacky function/template?

[1] http://projects.puppetlabs.com/projects/puppet/wiki/Ldap_Nodes

Jesús M. Navarro

unread,
May 7, 2010, 4:16:03 PM5/7/10
to puppet...@googlegroups.com
On Friday 07 May 2010 19:54:18 donavan wrote:
> On May 6, 4:31 pm, donavan <dona...@desinc.net> wrote:
> > Am I missing some clever way to use variables containing a dash in the
> > name?
> >
> > We're using LDAP nodes I may have a node like this example:
>
> ..
>
> > And I'd like to access 'console-port' as a variable in a manifest.
>
> Reading over I realize this may not be clear to people not using
> LdapNodes[1]. "All attributes on the LDAP nodes are assigned as
> variables in the Puppet configuration". This gives you puppet
> variables like $ipHostNumber for free.
>
> I have an LDAP attribute I need to check from inside my manifest. The
> issue is the attribute name contains a dash. So I can't use the
> regular semantics of $<attribute name> to access it. Any way to get
> this attribute without a hacky function/template?

Won't use the ${variable-name} version do the trick?
Cheers.

donavan

unread,
May 7, 2010, 9:59:58 PM5/7/10
to Puppet Users
On May 7, 1:16 pm, "Jesús M. Navarro" <jesus.nava...@andago.com>
wrote:
> Won't use the ${variable-name} version do the trick?
> Cheers.

I tried that initially, but it wouldn't pass --parseonly (.24.8) so I
didn't commit it. Let me check manually..
Yeah, parseonly and actual catalog compilation both fail:

err: Could not parse for environment production: Could not match '$
{dns-ns}' at init.pp:38
Reply all
Reply to author
Forward
0 new messages