Skip to content

Commit

Permalink
Add bolt inventory plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Dec 12, 2019
1 parent 1bec07a commit a27e6c2
Show file tree
Hide file tree
Showing 7 changed files with 605 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,50 @@ Example: `bolt task run sensu::install_agent backend=sensu_backend:8081 subscrip

Example: `bolt task run sensu::install_agent backend=sensu_backend:8081 subscription=windows output=true --nodes windows`

### Bolt Inventory

This module provides a plugin to populate Bolt v2 inventory targets.

In order to use the `sensu` inventory plugin the host executing Bolt must have `sensuctl` configured, see [Basic Sensu CLI](#basic-sensu-cli).

Example of configuring the Bolt inventory with two groups. The `linux` group pulls Sensu Go entities in the `default` namespace with the `linux` subscription. The `linux-qa` group is the same as `linux` group but instead pulling entities from the `qa` namespace.

```yaml
version: 2
groups:
- name: linux
targets:
- _plugin: sensu
namespace: default
subscription: linux
- name: linux-qa
targets:
- _plugin: sensu
namespace: qa
subscription: linux
```
If your entities have more than one network interface it may be necessary to specify the order of interfaces to search when looking for the IP address:
```yaml
version: 2
groups:
- name: linux
targets:
- _plugin: sensu
namespace: default
subscription: linux
interface_list:
- eth0
- eth1
```
The following rules for interface matching determine the value used for `uri`.

1. If `interface_list` was defined then find first match
1. If `interface_list` not defined and only one interface, use that as ipaddress
1. If `interface_list` is not defined and more than one interface, use name

## Reference

### Facts
Expand Down
1 change: 1 addition & 0 deletions bolt_plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
37 changes: 37 additions & 0 deletions spec/acceptance/sensu_bolt_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,40 @@ class { '::sensu::agent':
end
end
end

describe 'sensu bolt inventory', if: RSpec.configuration.sensu_full do
backend = hosts_as('sensu_backend')[0]
agent = hosts_as('sensu_agent')[0]
context 'setup' do
it 'should work without errors' do
agent_pp = <<-EOS
class { '::sensu::agent':
backends => ['sensu_backend:8081'],
}
EOS
pp = <<-EOS
include ::sensu::backend
#{agent_pp}
EOS
apply_manifest_on(agent, agent_pp, :catch_failures => true)
apply_manifest_on(backend, pp, :catch_failures => true)
inventory_cfg1 = <<-EOS
version: 2
groups:
- name: linux
targets:
- _plugin: sensu
EOS
create_remote_file(backend, '/root/.puppetlabs/bolt/inventory1.yaml', inventory_cfg1)
end
end

context 'inventory' do
it 'produces inventory' do
on backend, 'bolt inventory show --targets linux --format json -i /root/.puppetlabs/bolt/inventory1.yaml' do
data = JSON.parse(stdout)
expect(data["count"]).to eq(2)
end
end
end
end
Loading

0 comments on commit a27e6c2

Please sign in to comment.