puppetlabs / puppetlabs-node_manager

Create and manage PE node groups as resources.
Apache License 2.0
10 stars 21 forks source link

Can't remove parameters from node group classes #25

Closed Sharpie closed 7 years ago

Sharpie commented 7 years ago

Tried a couple ways of removing a parameter from the "PE Infrastructure" node:

node_group { 'PE Infrastructure':
  ensure               => 'present',
  classes              => {'puppet_enterprise' => {
    'mcollective_middleware_hosts' => undef
  }},
  environment          => 'production',
  override_environment => 'false',
  parent               => 'All Nodes',
}

Result: mcollective_middleware_hosts parameter is set to the string "undef".

node_group { 'PE Infrastructure':
  ensure               => 'present',
  classes              => {'puppet_enterprise' => {}},
  environment          => 'production',
  override_environment => 'false',
  parent               => 'All Nodes',
}

Node manager produces a message indicating that all parameters are being removed from the group:

Notice: /Stage[main]/Main/Node_group[PE Infrastructure]/classes: classes changed {'puppet_enterprise' => {'certificate_authority_host' => 'peamq-mom.peamq.vlan', 'console_host' => 'peamq-mom.peamq.vlan', 'database_host' => 'peamq-mom.peamq.vlan', 'mcollective_middleware_hosts' => 'undef', 'pcp_broker_host' => 'peamq-mom.peamq.vlan', 'puppet_master_host' => 'peamq-mom.peamq.vlan', 'puppetdb_host' => 'peamq-mom.peamq.vlan', 'send_analytics_data' => 'false'}} to '{"puppet_enterprise"=>{}}'

But, no change actually happens.

Not sure the second one should work, but it would be nice to have a way of explicitly removing a parameter from a class in a node group.

WhatsARanjit commented 7 years ago

Starting here.

# puppet resource node_group 'Canary group'
node_group { 'Canary group':
  ensure               => 'present',
  classes              => {'test_module' => {'foo' => 'hi'}},
  description          => 'testing new version',
  environment          => 'testing',
  id                   => '8a38e581-be84-4c96-8c89-68351e6561a0',
  override_environment => 'true',
  parent               => 'All Nodes',
}
WhatsARanjit commented 7 years ago

Trying curl:

# /usr/bin/curl -s -X POST \
> --cert $(puppet config print hostcert) \
> --key $(puppet config print hostprivkey) \
> --cacert $(puppet config print cacert) \
> -H "Content-Type: application/json" \
> -X POST --data '{ "classes": { "test_module": {} }  }' \
> https://$(puppet config print server):4433/classifier-api/v1/groups/8a38e581-be84-4c96-8c89-68351e6561a0
{"description":"testing new version","parent":"00000000-0000-4000-8000-000000000000","environment_trumps":true,"name":"Canary group","variables":{},"id":"8a38e581-be84-4c96-8c89-68351e6561a0","environment":"production","classes":{"test_module":{"foo":"hi"}}}

Doesn't update it.

WhatsARanjit commented 7 years ago

Ok so POSTing a null seems to obliterate the classes hash?

# /usr/bin/curl -s -X POST \
> --cert $(puppet config print hostcert) \
> --key $(puppet config print hostprivkey) \
> --cacert $(puppet config print cacert) \
> -H "Content-Type: application/json" \
> --data '{ "classes": { "test_module": null }  }' \
> https://$(puppet config print server):4433/classifier-api/v1/groups/8a38e581-be84-4c96-8c89-68351e6561a0
{"description":"testing new version","parent":"00000000-0000-4000-8000-000000000000","environment_trumps":true,"name":"Canary group","variables":{},"id":"8a38e581-be84-4c96-8c89-68351e6561a0","environment":"production","classes":{}}

# puppet resource node_group 'Canary group'
node_group { 'Canary group':
  ensure               => 'present',
  description          => 'testing new version',
  environment          => 'production',
  id                   => '8a38e581-be84-4c96-8c89-68351e6561a0',
  override_environment => 'true',
  parent               => 'All Nodes',
}
Sharpie commented 7 years ago

Yeah, POSTing a null for the params hash will take out an entire class. POSTing a null for a specific parameter should delete only that parameter:

The classes and variables keys of the delta will be merged with the node group, and then any keys of the resulting object that have a null value will be deleted. This allows you to remove classes, class parameters, or variables from the node group by setting them to null in the delta

https://docs.puppet.com/pe/latest/nc_groups.html#post-v1groupsid

WhatsARanjit commented 7 years ago

Merged #29