puppetlabs/bolt

Bolt puppetdb plugin example usage

pr3c0g opened this issue · 5 comments

Describe the Change You Would Like

The example usage section for the puppetdb plugin mentions target_mapping with both alias and name, but at least in my environment, this exact code will result in an error:

targets:
  - _plugin: puppetdb
    query: "inventory[certname] { facts.osfamily = 'RedHat' }"
    target_mapping:
      alias: facts.hostname
      name: certname

Error:

Target test00-00.domain.com does not have a host

Changing the target_mapping above to have uri instead of name makes it work.
I'm not sure I understand the error message, but I wanted to leave my suggestion with the way that is working for me.

Thank you!

The example you pasted in here is just a snippet from the complete example in the docs https://github.com/puppetlabs/bolt/blob/main/documentation/supported_plugins.md#example-usage-2

The complete example is:

targets:
  - _plugin: puppetdb
    query: "inventory[certname] { facts.osfamily = 'RedHat' }"
    target_mapping:
      alias: facts.hostname
      name: certname
      facts:
        custom_fact: facts.custom_fact
      features:
        - facts.custom_feature
      config:
        ssh:
          host: facts.networking.interfaces.en0.ipaddress
      vars:
        puppetversion: facts.puppetversion

The idea here was to show a real example of the the different places you can swap in values from pdb in creating targets. IN this case if we had swapped in uri instead of name in the top level of target_mapping then the host under config.ssh would not be respected. So in the context of the full example this would work.

I am open to having another simpler example that does not attempt to demonstrate every single way to interpolate data, but I would like to keep the existing one as it is a good example of how to use every single key.

You're right. I didn't understand from this example that when name is used instead of uri, then config needs to be explicitly set including a host.

Does this mean that with uri, a default hash of configs will be used?

The nuance here is the difference between name and uri. Excerpt from docs https://puppet.com/docs/bolt/latest/inventory_files.html

The URI of the target. Bolt uses the uri to establish a connection to the target. Required when specifying a target using a hash, unless you specify a name and configure a hostname using host in the target's transport configuration.

The uri is ultimately the most specific (and therefore the highest precedence) way to specify a target. For example a target like uri: ssh://foo:bar@example.com:22 has all kinds of connection information in it (transport, user, password, port, etc).

Thank you for the explanation. I will close this issue as I have no suggestion on how to improve, I should've read more.

Sounds good, Happy to chat more about this (or any other bolt issues) on community slack!