fix: auth problem with new sensu version

This commit is contained in:
Adrien Waksberg 2020-03-30 22:40:19 +02:00
parent 69a6d0fb03
commit 632258e746
15 changed files with 131 additions and 345 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
.kitchen/* .kitchen/*
*.pyc

View file

@ -1,37 +0,0 @@
---
# <% os = ENV['OS'] || 'debian9' %>
# <% ansible = ENV['ANSIBLE_VERSION'] || '2.8' %>
# <% command = os == 'centos7' ? '/usr/sbin/init' : '/bin/systemd' %>
driver:
name: docker_cli
transport:
name: docker_cli
provisioner:
name: ansible_playbook
hosts: localhost
require_ansible_repo: false
require_ansible_omnibus: false
require_chef_for_busser: true
ansible_verbose: false
ansible_inventory: ./test/integration/inventory
platforms:
- name: <%= os %>
driver_config:
image: "nishiki/<%= os %>:ansible-<%= ansible %>"
command: <%= command %>
volume:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
security_opt: seccomp=unconfined
# <% if os == 'debian9' %>
provisioner:
extra_vars:
sensu_repository_system: ubuntu
sensu_repository_release: xenial
# <% end %>
suites:
- name: default

View file

@ -1,38 +0,0 @@
---
AllCops:
Exclude:
- db/**/*
- config/**/*
- Vagrantfile
TargetRubyVersion: 2.4
Naming/AccessorMethodName:
Enabled: false
Lint/RescueWithoutErrorClass:
Enabled: false
Metrics/LineLength:
Max: 120
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Style/NumericLiteralPrefix:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Style/CommandLiteral:
Enabled: true
EnforcedStyle: percent_x
Style/Documentation:
Enabled: false

View file

@ -1,32 +1,29 @@
--- ---
sudo: required sudo: required
language: ruby dist: bionic
addons:
apt:
packages:
- python3
- python3-pip
- python3-setuptools
env: env:
- OS=debian9 ANSIBLE_VERSION=2.5 - ANSIBLE_VERSION=2.7.16
- OS=debian9 ANSIBLE_VERSION=2.6 - ANSIBLE_VERSION=2.8.8
- OS=debian9 ANSIBLE_VERSION=2.7 - ANSIBLE_VERSION=2.9.4
- OS=debian9 ANSIBLE_VERSION=2.8
- OS=ubuntu18.04 ANSIBLE_VERSION=2.7
- OS=ubuntu16.04 ANSIBLE_VERSION=2.7
- OS=centos7 ANSIBLE_VERSION=2.7
services: services:
- docker - docker
before_install: before_install:
- bundle install - sudo pip3 install ansible==${ANSIBLE_VERSION}
- sudo pip install --upgrade pip - sudo pip3 install molecule 'molecule[docker]' docker testinfra ansible-lint yamllint
- sudo pip install yamllint
- sudo pip install ansible-lint
- git clone https://github.com/ansible/galaxy-lint-rules.git - git clone https://github.com/ansible/galaxy-lint-rules.git
script: script:
- kitchen conv - ansible --version
- kitchen conv | grep changed=0 - molecule test
- kitchen verify
- ansible-lint -r galaxy-lint-rules/rules .
- yamllint .
notifications: notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/ webhooks: https://galaxy.ansible.com/api/v1/notifications/

View file

@ -5,6 +5,14 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
## [Unreleased] ## [Unreleased]
### Fixed
- add compatibily with new sensu version
### Changed
- test: replace kitchen to molecule
## [1.2.0] - 2019-06-22 ## [1.2.0] - 2019-06-22
- feat: add support for ansible 2.8 - feat: add support for ansible 2.8

View file

@ -1,8 +0,0 @@
source 'https://rubygems.org'
group :development do
gem 'kitchen-ansible'
gem 'kitchen-docker_cli'
gem 'rubocop', '0.50.0'
gem 'test-kitchen'
end

View file

@ -1,130 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
bcrypt_pbkdf (1.0.1)
builder (3.2.3)
ed25519 (1.2.4)
equatable (0.6.0)
erubis (2.7.0)
ffi (1.11.1)
gssapi (1.3.0)
ffi (>= 1.0.1)
gyoku (1.3.1)
builder (>= 2.1.2)
httpclient (2.8.3)
kitchen-ansible (0.50.0)
net-ssh (>= 3)
test-kitchen (>= 1.4)
kitchen-docker_cli (0.19.0)
test-kitchen (>= 1.3)
license-acceptance (1.0.13)
pastel (~> 0.7)
tomlrb (~> 1.2)
tty-box (~> 0.3)
tty-prompt (~> 0.18)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
mixlib-install (3.11.18)
mixlib-shellout
mixlib-versioning
thor
mixlib-shellout (2.4.4)
mixlib-versioning (1.2.7)
multi_json (1.13.1)
necromancer (0.5.0)
net-scp (2.0.0)
net-ssh (>= 2.6.5, < 6.0.0)
net-ssh (5.2.0)
net-ssh-gateway (2.0.0)
net-ssh (>= 4.0.0)
nori (2.6.0)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
pastel (0.7.3)
equatable (~> 0.6)
tty-color (~> 0.5)
powerpack (0.1.2)
rainbow (2.2.2)
rake
rake (12.3.2)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.10.1)
rubyntlm (0.6.2)
rubyzip (1.2.3)
strings (0.1.5)
strings-ansi (~> 0.1)
unicode-display_width (~> 1.5)
unicode_utils (~> 1.4)
strings-ansi (0.1.0)
test-kitchen (2.2.5)
bcrypt_pbkdf (~> 1.0)
ed25519 (~> 1.2)
license-acceptance (~> 1.0, >= 1.0.11)
mixlib-install (~> 3.6)
mixlib-shellout (>= 1.2, < 3.0)
net-scp (>= 1.1, < 3.0)
net-ssh (>= 2.9, < 6.0)
net-ssh-gateway (>= 1.2, < 3.0)
thor (~> 0.19)
winrm (~> 2.0)
winrm-elevated (~> 1.0)
winrm-fs (~> 1.1)
thor (0.20.3)
tomlrb (1.2.8)
tty-box (0.4.0)
pastel (~> 0.7.2)
strings (~> 0.1.5)
tty-cursor (~> 0.7)
tty-color (0.5.0)
tty-cursor (0.7.0)
tty-prompt (0.19.0)
necromancer (~> 0.5.0)
pastel (~> 0.7.0)
tty-reader (~> 0.6.0)
tty-reader (0.6.0)
tty-cursor (~> 0.7)
tty-screen (~> 0.7)
wisper (~> 2.0.0)
tty-screen (0.7.0)
unicode-display_width (1.6.0)
unicode_utils (1.4.0)
winrm (2.3.2)
builder (>= 2.1.2)
erubis (~> 2.7)
gssapi (~> 1.2)
gyoku (~> 1.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (>= 1.6.1, < 3.0)
nori (~> 2.0)
rubyntlm (~> 0.6.0, >= 0.6.1)
winrm-elevated (1.1.1)
winrm (~> 2.0)
winrm-fs (~> 1.0)
winrm-fs (1.3.2)
erubis (~> 2.7)
logging (>= 1.6.1, < 3.0)
rubyzip (~> 1.1)
winrm (~> 2.0)
wisper (2.0.0)
PLATFORMS
ruby
DEPENDENCIES
kitchen-ansible
kitchen-docker_cli
rubocop (= 0.50.0)
test-kitchen
BUNDLED WITH
1.16.0

View file

@ -233,25 +233,13 @@ Notice: for debian9 set `sensu_repository_system` to `ubuntu` and `sensu_reposit
``` ```
## Development ## Development
### Test syntax with yamllint
* install `python` and `python-pip` ### Test with molecule and docker
* install yamllint `pip install yamllint`
* run `yamllint .`
### Test syntax with ansible-lint
* install `python` and `python-pip`
* install yamllint `pip install ansible-lint`
* run `ansible-lint .`
### Tests with docker
* install [docker](https://docs.docker.com/engine/installation/) * install [docker](https://docs.docker.com/engine/installation/)
* install ruby * install `python3` and `python3-pip`
* install bundler `gem install bundler` * install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint`
* install dependencies `bundle install` * run `molecule test`
* run the tests `kitchen test`
## License ## License

View file

@ -19,7 +19,7 @@ class SensuApi:
if r.status_code == 401: if r.status_code == 401:
raise Exception('Authentification has failed') raise Exception('Authentification has failed')
self.headers = { 'Authorization': r.json()['access_token'] } self.headers = { 'Authorization': 'Bearer %s' % (r.json()['access_token']) }
def get(self, path): def get(self, path):
r = requests.get( r = requests.get(

View file

@ -1,7 +1,12 @@
--- ---
- hosts: default - name: Converge
connection: local hosts: all
roles:
- ansible-role-sensu
vars: vars:
#sensu_api_password: test
sensu_repository_system: ubuntu
sensu_repository_release: xenial
sensu_no_log: false sensu_no_log: false
sensu_backend: yes sensu_backend: yes
sensu_agent_redact: sensu_agent_redact:
@ -67,6 +72,3 @@
- list - list
resources: resources:
- '*' - '*'
roles:
- ansible-role-sensu

View file

@ -0,0 +1,18 @@
---
driver:
name: docker
platforms:
- name: debian10
image: nishiki/debian10:molecule
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
command: /bin/systemd
capabilities:
- SYS_ADMIN
lint: |
set -e
yamllint .
ansible-lint
verifier:
name: testinfra

View file

@ -0,0 +1,60 @@
import re
import testinfra.utils.ansible_runner
def test_packages(host):
for package_name in ['sensu-go-agent', 'sensu-go-cli', 'sensu-go-backend']:
package = host.package(package_name)
assert package.is_installed
def test_services(host):
for service_name in ['sensu-backend', 'sensu-agent']:
service = host.service(service_name)
assert service.is_running
assert service.is_enabled
def test_sockets(host):
for port in [3000, 8080, 8081]:
socket = host.socket('tcp://0.0.0.0:%d' % (port))
assert socket.is_listening
def test_configure_sensuctl(host):
cmd = host.run('sensuctl configure -n --password "P@ssw0rd!" --url http://127.0.0.1:8080 --username admin --format tabular')
assert cmd.succeeded
def test_sensu_namespace(host):
cmd = host.run('sensuctl namespace list')
assert cmd.succeeded
assert 'production' in cmd.stdout
assert 'dev' in cmd.stdout
def test_sensu_user(host):
cmd = host.run('sensuctl user list')
assert cmd.succeeded
assert re.search('johndoe.*\\s+devops,users\\s+.*true', cmd.stdout)
def test_sensu_entity(host):
cmd = host.run('sensuctl entity info debian10 --format json')
assert cmd.succeeded
assert '"supersecret": "REDACTED"' in cmd.stdout
def test_sensu_check(host):
for namespace in ['production', 'dev']:
cmd = host.run('sensuctl asset list --namespace %s' % namespace)
assert cmd.succeeded
assert re.search('superasset.*\\s+.*test.sh\\s+cf83e13', cmd.stdout)
cmd = host.run('sensuctl mutator list --namespace %s' % namespace)
assert cmd.succeeded
assert re.search('transform.*\\s+.*/path/value_to_csv', cmd.stdout)
cmd = host.run('sensuctl handler list --namespace %s' % namespace)
assert cmd.succeeded
assert re.search('mail.*\\s+pipe\\s+.*echo test | mail -s coucou\\s+', cmd.stdout)
cmd = host.run('sensuctl check list --namespace %s' % namespace)
assert cmd.succeeded
assert re.search('ping.*\\s+ping -c 1 127.0.0.1\\s+60\\s+.*\\s+linux\\s+', cmd.stdout)
cmd = host.run('sensuctl filter list --namespace %s' % namespace)
assert cmd.succeeded
assert re.search('state_changed.*\\s+allow\\s+\\(event.check.occurrences == 1\\)', cmd.stdout)

View file

@ -37,6 +37,24 @@
delay: 5 delay: 5
tags: sensu tags: sensu
- name: init backend
command:
cmd: sensu-backend init
creates: /etc/sensu/.backend-init
environment:
SENSU_BACKEND_CLUSTER_ADMIN_USERNAME: '{{ sensu_api_user }}'
SENSU_BACKEND_CLUSTER_ADMIN_PASSWORD: '{{ sensu_api_password }}'
tags: sensu
- name: hold init
copy:
content: ''
dest: /etc/sensu/.backend-init
owner: root
group: root
mode: 0600
tags: sensu
- name: manage cluster roles - name: manage cluster roles
sensugo_cluster_role: sensugo_cluster_role:
name: '{{ item.name }}' name: '{{ item.name }}'

View file

@ -1,90 +0,0 @@
require 'serverspec'
set :backend, :exec
puts
puts '================================'
puts %x(ansible --version)
puts '================================'
%w[
sensu-go-agent
sensu-go-cli
sensu-go-backend
].each do |package|
describe package(package) do
it { should be_installed }
end
end
%w[
sensu-agent
sensu-backend
].each do |service|
describe service(service) do
it { should be_enabled }
it { should be_running }
it { should be_running.under('systemd') }
end
end
[3000, 8080, 8081].each do |port|
describe port(port) do
it { should be_listening.with('tcp6') }
end
end
describe command(
'sensuctl configure -n --password "P@ssw0rd!" ' \
'--url http://127.0.0.1:8080 --username admin --format tabular'
) do
its(:exit_status) { should eq 0 }
end
describe command('sensuctl namespace list') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match 'production' }
its(:stdout) { should match 'dev' }
end
describe command('sensuctl user list') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/johndoe.*\s+devops,users\s+.*true/) }
end
describe command('sensuctl entity info localhost --format json') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/"supersecret": "REDACTED"/) }
end
%w[production dev].each do |namespace|
describe command("sensuctl asset list --namespace #{namespace}") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/superasset.*\s+.*test.sh\s+cf83e13/) }
end
describe command("sensuctl mutator list --namespace #{namespace}") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(%r{transform.*\s+.*/path/value_to_csv}) }
end
describe command("sensuctl handler list --namespace #{namespace}") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/mail.*\s+pipe\s+.*echo test \| mail -s coucou\s+/) }
end
describe command("sensuctl check list --namespace #{namespace}") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/ping.*\s+ping -c 1 127.0.0.1\s+60\s+.*\s+linux\s+/) }
end
describe command("sensuctl filter list --namespace #{namespace}") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/state_changed.*\s+allow\s+event\.check\.occurrences == 1/) }
end
end
describe command('sensuctl cluster-role list') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/view.*\s+1/) }
end

View file

@ -1,2 +0,0 @@
[default]
localhost