voxpupuli / puppet-wildfly

Puppet module to install, configure and manage Wildfly (8/9/10+), JBoss EAP (6.1+/7.0+) and some Wildfly based products like apiman, Keycloak and Infinispan.
Apache License 2.0
29 stars 79 forks source link

Cannot create naming context due to naming issues #179

Closed cfrantsen closed 7 years ago

cfrantsen commented 7 years ago

I'm trying to create a naming context like this, where name is java:global/ldap/bmk

wildfly_resource { "/subsystem=naming/binding=${name}":
    host => '127.0.0.1',
    port => '9990',
    password => 'xxx',
    username => 'xxx',
    state => {
        binding-type => 'external-context',
        cache        => false,
        'class'      => 'javax.naming.directory.InitialDirContext',
        module       => 'org.jboss.as.naming',
        environment  => {
            'java.naming.factory.initial'         => 'com.sun.jndi.ldap.LdapCtxFactory',
            'java.naming.provider.url'            => join(prefix($servers, 'ldap://'), ' '),
            'java.naming.security.authentication' => 'simple',
            'java.naming.security.principal'      => $bind_dn,
            'java.naming.security.credentials'    => $bind_credential,
            'com.sun.jndi.ldap.connect.pool'      => true,
        },
    }
}

This results in the following error:

Error: Could not set 'present' on ensure: Failed with: WFLYNAM0048: Invalid binding name java, name must start with one of [java:global, java:jboss, java:/] for ......

So I try to escape the colon and slashes in the name using regsubst($name, '(/|:)', '\\\1', 'G') but then I get this error instead:

Could not evaluate: undefined method `elements' for nil:NilClass

This used to work in earlier versions (0.5 something) but stopped working when I tried upgrading to the newest one. It looks to be related to #177.

Any suggestions on how I can get this working?

jairojunior commented 7 years ago

The proper JBoss-CLI syntax to add this resource is: /subsystem=naming/binding="java:global/ldap/bmx":add() (i.e. you need to quote the value)

I changed to it, tried to apply, but it turns out the request should be cleaning this value before submitting it. A simple gsub('"', '') at line 37 of CLICommand was enough to pass.

So, I'll add a spec for this scenario, fix the code and release it as soon as I can.

Thanks for your time. Your report will improve this module. :+1:

jairojunior commented 7 years ago

Just pushed to master. Could you test it?

cfrantsen commented 7 years ago

Tried master with the following syntax, but still get an error. wildfly_resource { "/subsystem=naming/binding=\"${name}\"":

/Wildfly_resource[/subsystem=naming/binding="java:global/ldap/bmk"]: Could not evaluate: undefined method `elements' for nil:NilClass

jairojunior commented 7 years ago

My bad. I thought you're using wildfly::resource, but you're using wildfly_resource.

Here is what you can do temporarily:

wildfly_resource { '/subsystem=naming/binding=java:global/ldap/bmk':
  username => 'puppet',
  password => 'puppet',
  host     => '127.0.0.1',
  port     => '9990',
  path     => '/subsystem=naming/binding="java:global/ldap/bmk"',
  state    => {
      'binding-type' => 'external-context',
      'cache'        => false,
      'class'        => 'javax.naming.directory.InitialDirContext',
      'module'       => 'org.jboss.as.naming',
      'environment'  => {
          'java.naming.factory.initial'         => 'com.sun.jndi.ldap.LdapCtxFactory',
          'java.naming.provider.url'            => 'ldap://',
          'java.naming.security.authentication' => 'simple',
          'java.naming.security.principal'      => 'abc',
          'java.naming.security.credentials'    => 'abc',
          'com.sun.jndi.ldap.connect.pool'      => true,
      },
  }
}

The problem is that wildfly_resource uses a composite namevar path:host:port to allow management of multiple instances from a single Puppet node, but it's conflicting with java:global, so, you have to override path, host and port in order to make it work.

cfrantsen commented 7 years ago

I'l give this a try when I get to the office tomorrow. Thanks!

cfrantsen commented 7 years ago

Works great when using explicit path, thanks.