Using tags in Puppet Bolt aws_inventory target_mapping

June 5, 2021 

We're migrating away from Ansible to Puppet Bolt and the fact that Ansible updates broke the old inventory script expedited that process. While that inventory script was quite rudimentary, it was able to automatically add human-readable names to the EC2 instance names. So, for example, you could target a node using "server_example_org" if the Name tag was set to "".

Puppet Bolt's aws_inventory seemed to lack that feature, but after taking a good look at its code this was just a case of missing documentation, which I fixed in this PR. Here's an example of inventory.yaml for Bolt that maps the value of the "Name" tag to the name of the Bolt target:

  - name: aws
     - _plugin: aws_inventory
         _plugin: env_var
         var: AWS_DEFAULT_REGION
         name: tags.Name
         uri: public_ip_address

This makes your inventory much nicer and more usable for humans:

$ bolt inventory show
  --- snip ---

Now you can target a node trivially using its name instead of IP:

$ bolt command run "uname"
Samuli Seppänen
Samuli Seppänen
Author archive