diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e91a45ce78a77e01b7eab1fd7ea3a3cf6e750fc8..40017a3ddfc3e409d640ab8536097de55d685c7c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,13 +2,20 @@ sha: 97b88d9610bcc03982ddac33caba98bb2b751f5f hooks: - id: check-added-large-files - - id: check-json - - id: check-xml - id: check-yaml - id: check-merge-conflict - id: flake8 - repo: https://github.com/adarnimrod/shell-pre-commit - sha: e48c7fbdadf14a548dcbda32895b67f90fa0f12b + sha: v0.1.0 hooks: - id: shell-lint files: collectd/collectd_facts|nginx/nginx_facts|ssl/dhparams +- repo: https://github.com/adarnimrod/ansible-pre-commit.git + sha: v0.4.0 + hooks: + - id: ansible-syntax-check +- repo: https://github.com/willthames/ansible-lint + sha: 959ab0f525e9abb19cf75f34381015cf33695f61 + hooks: + - id: ansible-lint + files: playbook.yml diff --git a/.travis.yml b/.travis.yml index a304f5e21f7bc178799b0e64c90441bffcf3b5da..d4673503a24c52fd5fbceea2552aced248c60295 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,23 @@ language: python python: "2.7" dist: trusty sudo: false +services: [docker] +cache: + - pip + - directories: + - $HOME/.pre-commit + +env: + - DOCKER=ubuntu:trusty + - DOCKER=ubuntu:xenial + - DOCKER=debian:jessie install: - - pip install pre_commit + - pip install pre_commit ansible + +before_script: + - docker run --name $(echo $DOCKER | sed 's/:/_/g') $DOCKER script: - pre-commit run --all-files + - ansible-playbook -i $(echo $DOCKER | sed 's/:/_/g'), playbook.yml diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000000000000000000000000000000000000..b6d3a7e457b49292d5795a17fee30f145ac009bc --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,3 @@ +[defaults] +library = ./ +host_key_checking = False diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000000000000000000000000000000000000..790dddd84dea4d759f43b6f5b4869bcded2a966c --- /dev/null +++ b/playbook.yml @@ -0,0 +1,73 @@ +--- +- hosts: all + tasks: + - name: APT install + apt: + name: + - collectd + - nginx + - openssl + state: present + update_cache: yes + + - name: Collectd facts + collectd_facts: + register: collectd_facts + + - name: Assertions + assert: + that: + - collectd_facts is defined + - major in collectd_facts + - collectd_facts.major is number + - collectd_facts.changed == False + + - name: Nginx facts + nginx_facts: + register: nginx_facts + + - name: Assertions + assert: + that: + - nginx_facts is defined + - version in nginx_facts + - major in nginx_facts + - nginx_facts.major is number + - nginx_facts.changed == False + + - name: DH params for missing file + ignore_errors: True + dhparams: + path: /etc/ssl/dhparams.pem + register: missing_dhparams + + - name: Assertions + assert: + that: + - missing_dhparams is defined + - bits in missing_dhparams + - missing_dhparams.bits == 0 + - failed in missing_dhparams + - missing_dhparams.failed == True + - path in missing_dhparams + - missing_dhparams.path == '/etc/ssl/dhparams.pem' + + - name: Generate DH params + command: openssl dhparam -out /etc/ssl/dhparams.pem 2048 + changed_when: True + + - name: DH params for existing file + dhparams: + path: /etc/ssl/dhparams.pem + register: existing_dhparams + + - name: Assertions + assert: + that: + - existing_dhparams is defined + - bits in existing_dhparams + - existing_dhparams.bits == 2048 + - failed in existing_dhparams + - existing_dhparams.failed == False + - path in existing_dhparams + - existing_dhparams.path == '/etc/ssl/dhparams.pem'