Skip to content

Commit a27e6c2

Browse files
committed
Add bolt inventory plugin
1 parent 1bec07a commit a27e6c2

File tree

7 files changed

+605
-0
lines changed

7 files changed

+605
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,50 @@ Example: `bolt task run sensu::install_agent backend=sensu_backend:8081 subscrip
765765

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

768+
### Bolt Inventory
769+
770+
This module provides a plugin to populate Bolt v2 inventory targets.
771+
772+
In order to use the `sensu` inventory plugin the host executing Bolt must have `sensuctl` configured, see [Basic Sensu CLI](#basic-sensu-cli).
773+
774+
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.
775+
776+
```yaml
777+
version: 2
778+
groups:
779+
- name: linux
780+
targets:
781+
- _plugin: sensu
782+
namespace: default
783+
subscription: linux
784+
- name: linux-qa
785+
targets:
786+
- _plugin: sensu
787+
namespace: qa
788+
subscription: linux
789+
```
790+
791+
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:
792+
793+
```yaml
794+
version: 2
795+
groups:
796+
- name: linux
797+
targets:
798+
- _plugin: sensu
799+
namespace: default
800+
subscription: linux
801+
interface_list:
802+
- eth0
803+
- eth1
804+
```
805+
806+
The following rules for interface matching determine the value used for `uri`.
807+
808+
1. If `interface_list` was defined then find first match
809+
1. If `interface_list` not defined and only one interface, use that as ipaddress
810+
1. If `interface_list` is not defined and more than one interface, use name
811+
768812
## Reference
769813

770814
### Facts

bolt_plugin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

spec/acceptance/sensu_bolt_tasks_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,40 @@ class { '::sensu::agent':
284284
end
285285
end
286286
end
287+
288+
describe 'sensu bolt inventory', if: RSpec.configuration.sensu_full do
289+
backend = hosts_as('sensu_backend')[0]
290+
agent = hosts_as('sensu_agent')[0]
291+
context 'setup' do
292+
it 'should work without errors' do
293+
agent_pp = <<-EOS
294+
class { '::sensu::agent':
295+
backends => ['sensu_backend:8081'],
296+
}
297+
EOS
298+
pp = <<-EOS
299+
include ::sensu::backend
300+
#{agent_pp}
301+
EOS
302+
apply_manifest_on(agent, agent_pp, :catch_failures => true)
303+
apply_manifest_on(backend, pp, :catch_failures => true)
304+
inventory_cfg1 = <<-EOS
305+
version: 2
306+
groups:
307+
- name: linux
308+
targets:
309+
- _plugin: sensu
310+
EOS
311+
create_remote_file(backend, '/root/.puppetlabs/bolt/inventory1.yaml', inventory_cfg1)
312+
end
313+
end
314+
315+
context 'inventory' do
316+
it 'produces inventory' do
317+
on backend, 'bolt inventory show --targets linux --format json -i /root/.puppetlabs/bolt/inventory1.yaml' do
318+
data = JSON.parse(stdout)
319+
expect(data["count"]).to eq(2)
320+
end
321+
end
322+
end
323+
end

0 commit comments

Comments
 (0)