Augeas: Duplicate declaration

201 views
Skip to first unread message

Reinaldo Lima

unread,
Jan 16, 2014, 4:15:01 PM1/16/14
to puppet...@googlegroups.com
Hi Everyone,

I'm trying to write a class that put some entries in "/etc/hosts" file as follow below:

class hosts {

        $netentry = {
                host01 => { iphost => '192.168.10.1', hostName => host01 },
                host02 => { iphost => '192.168.10.2', hostName => host02 },
                host03 => { iphost => '192.168.10.3', hostName => host03 },
        }

        define hostsinclude ($entry) {
               augeas { "hosts_include":
                       incl => "/etc/hosts",
                       lens => "Hosts.lns",
                       changes => [
                               "set /files/etc/hosts/01/ipaddr $entry[$name]['iphost']",
                               "set /files/etc/hosts/01/canonical$entry[$name]['hostName']",
                               ],
                       onlyif => "match */ipaddr[ . = $entry[$name]['iphost'] ] size == 0"
               }
        }

        hostsinclude { [
                'host01',
                'host02',
                'host03'
                ]:
                entry => $netentry
        }

}

and, when puppet compiles the manifest, I get the following error: 

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Augeas[hosts_include] is already declared in file /puppet/environments/production/modules/checklist/manifests/hosts.pp at line 10; cannot redeclare at /puppet/environments/production/modules/checklist/manifests/hosts.pp:29 on node

Someone can help me?

Thanks

Nick Cammorato

unread,
Jan 16, 2014, 6:47:01 PM1/16/14
to puppet...@googlegroups.com

Your augeas resource is always called hosts_include which is why it's doing that.  Try including the entry[name] in that resource name.

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/fe9040f2-54de-4f9c-9787-4736b37219d9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Andrey Kozichev

unread,
Jan 17, 2014, 2:10:16 AM1/17/14
to puppet...@googlegroups.com

another option to use create_resources('hostinclude',$netentry)

Reinaldo Lima

unread,
Jan 17, 2014, 10:21:48 AM1/17/14
to puppet...@googlegroups.com
With "create_resources" the error is:

Invalid parameter hostName on node

And including the entry[name] in the resource name:

Resource title must be a String, not Hash
 

=(

Andrey Kozichev

unread,
Jan 17, 2014, 1:07:34 PM1/17/14
to puppet...@googlegroups.com

ah, right you are supplying entire hash in your defined resource. Missed it.

If your defined resource would accept: name, iphost and hostname - then you can use create_resources to define all 3 entry.

Nick Cammorato

unread,
Jan 18, 2014, 7:18:06 PM1/18/14
to puppet...@googlegroups.com
Sorry, didn't realize it was a hash of hashes.  You just need the augeas resource to have a unique name - entry[$name][hostname] or ipaddress should work.

IE:
define a_thing {
  augeas { 'host_entry': }
}

a_thing { 'a': }
a_thing { 'b': }

Will generate an error like you are seeing.

define a_thing {
  augeas { "host_entry_${name}": }
}
a_thing {'a': }
a_thing {'b': }

Will not.


Reinaldo Lima

unread,
Jan 20, 2014, 12:51:02 PM1/20/14
to puppet...@googlegroups.com
Almost there! =)

My only change was '"host_entry_${name}" :' like you suggested,

everything else in the code is like my first post, and the error now is:

"Could not evaluate: uninitialized constant Augeas::NO_MODL_AUTOLOAD"


By the way, thank you so much for the help, this topic made me learn a lot about puppet =)
Reply all
Reply to author
Forward
0 new messages