diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..28f55c376e8c51ae9c85c5f89441f3ec4e35ff7d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,19 @@ +--- +image: adarnimrod/ci-images:docker + +stages: + - lint + +pre-commit: + stage: lint + image: adarnimrod/ci-images:pre-commit + variables: + XDG_CACHE_HOME: "$CI_PROJECT_DIR/.cache" + before_script: + # yamllint disable-line rule:line-length + - git clone https://git.shore.co.il/ansible/debian-bootstrap.git tests/roles/debian-bootstrap + script: + - pre-commit run --all-files + cache: + paths: + - .cache/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8986c29e9208b63ddcd7aaba215a8a7b6d9a312e..0f02cbec25e072ec1c12d862c1e771ddba27a203 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,24 +1,30 @@ -- repo: git://github.com/pre-commit/pre-commit-hooks - sha: v0.8.0 +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 hooks: - - id: check-added-large-files - - id: check-yaml - - id: check-merge-conflict - - id: flake8 -- repo: https://github.com/adarnimrod/shell-pre-commit - sha: v0.5.4 + - id: check-added-large-files + - id: check-executables-have-shebangs + - id: check-merge-conflict + + - repo: https://github.com/adarnimrod/shell-pre-commit + rev: v0.6.0 hooks: - - id: shell-lint - files: &shellscripts collectd/collectd_facts|nginx/nginx_facts|ssl/dhparams - - id: shellcheck - files: *shellscripts -- repo: https://github.com/adarnimrod/ansible-pre-commit.git - sha: v0.6.0 + - id: shell-lint + - id: shellcheck + + - repo: https://github.com/adarnimrod/ansible-pre-commit + rev: v0.10.0 hooks: - - id: ansible-syntax-check - files: &playbook tests/playbook.yaml -- repo: https://github.com/willthames/ansible-lint - sha: v3.4.13 + - id: ansible-syntax-check + files: tests/playbook.yaml + + - repo: https://github.com/myint/rstcheck + rev: master hooks: - - id: ansible-lint - files: *playbook + - id: rstcheck + + - repo: https://github.com/adrienverge/yamllint + rev: v1.25.0 + hooks: + - id: yamllint diff --git a/.travis.yml b/.travis.yml index 1073338a4bc1edcebb54e845cc4609c484c8233a..6f9ba9fe2c97fca31c425058441c0a629bbe9e8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,43 +8,43 @@ services: - docker group: beta cache: - - pip - - directories: - - $HOME/.pre-commit + - pip + - directories: + - $HOME/.pre-commit env: -- TOXENV: pre-commit -- TOXENV: ansible2.3.1.0-image_ubuntu_xenial -- TOXENV: ansible2.3.1.0-image_ubuntu_trusty -- TOXENV: ansible2.3.1.0-image_ubuntu_precise -- TOXENV: ansible2.3.1.0-image_debian_stretch -- TOXENV: ansible2.3.1.0-image_debian_jessie -- TOXENV: ansible2.3.1.0-image_debian_wheezy -- TOXENV: ansible2.2.3.0-image_ubuntu_xenial -- TOXENV: ansible2.2.3.0-image_ubuntu_trusty -- TOXENV: ansible2.2.3.0-image_ubuntu_precise -- TOXENV: ansible2.2.3.0-image_debian_stretch -- TOXENV: ansible2.2.3.0-image_debian_jessie -- TOXENV: ansible2.2.3.0-image_debian_wheezy -- TOXENV: ansible2.1.6.0-image_ubuntu_xenial -- TOXENV: ansible2.1.6.0-image_ubuntu_trusty -- TOXENV: ansible2.1.6.0-image_ubuntu_precise -- TOXENV: ansible2.1.6.0-image_debian_stretch -- TOXENV: ansible2.1.6.0-image_debian_jessie -- TOXENV: ansible2.1.6.0-image_debian_wheezy -- TOXENV: ansible2.0.2.0-image_ubuntu_xenial -- TOXENV: ansible2.0.2.0-image_ubuntu_trusty -- TOXENV: ansible2.0.2.0-image_ubuntu_precise -- TOXENV: ansible2.0.2.0-image_debian_stretch -- TOXENV: ansible2.0.2.0-image_debian_jessie -- TOXENV: ansible2.0.2.0-image_debian_wheezy + - TOXENV: pre-commit + - TOXENV: ansible2.3.1.0-image_ubuntu_xenial + - TOXENV: ansible2.3.1.0-image_ubuntu_trusty + - TOXENV: ansible2.3.1.0-image_ubuntu_precise + - TOXENV: ansible2.3.1.0-image_debian_stretch + - TOXENV: ansible2.3.1.0-image_debian_jessie + - TOXENV: ansible2.3.1.0-image_debian_wheezy + - TOXENV: ansible2.2.3.0-image_ubuntu_xenial + - TOXENV: ansible2.2.3.0-image_ubuntu_trusty + - TOXENV: ansible2.2.3.0-image_ubuntu_precise + - TOXENV: ansible2.2.3.0-image_debian_stretch + - TOXENV: ansible2.2.3.0-image_debian_jessie + - TOXENV: ansible2.2.3.0-image_debian_wheezy + - TOXENV: ansible2.1.6.0-image_ubuntu_xenial + - TOXENV: ansible2.1.6.0-image_ubuntu_trusty + - TOXENV: ansible2.1.6.0-image_ubuntu_precise + - TOXENV: ansible2.1.6.0-image_debian_stretch + - TOXENV: ansible2.1.6.0-image_debian_jessie + - TOXENV: ansible2.1.6.0-image_debian_wheezy + - TOXENV: ansible2.0.2.0-image_ubuntu_xenial + - TOXENV: ansible2.0.2.0-image_ubuntu_trusty + - TOXENV: ansible2.0.2.0-image_ubuntu_precise + - TOXENV: ansible2.0.2.0-image_debian_stretch + - TOXENV: ansible2.0.2.0-image_debian_jessie + - TOXENV: ansible2.0.2.0-image_debian_wheezy install: - - pip install tox-travis | cat + - pip install tox-travis | cat script: - - tox + - tox notifications: - email: false - on_failure: never + email: false + on_failure: never diff --git a/README.rst b/README.rst index 3c083eab058682547fa977ab131e5d07c7eb713b..911e4403020cc8a446606c22f7dd6cbf08f3f82a 100644 --- a/README.rst +++ b/README.rst @@ -1,11 +1,16 @@ ansible-modules ############### -.. image:: https://travis-ci.org/adarnimrod/ansible-modules.svg?branch=master - :target: https://travis-ci.org/adarnimrod/ansible-modules +.. image:: https://git.shore.co.il/ansible/ansible-modules/badges/master/pipeline.svg + :target: https://git.shore.co.il/ansible/ansible-modules/-/commits/master + :alt: pipeline status A repository of Ansible modules. +This project is deprecated. All of the modules in this repo have equivalents in +the Ansible project making them obsolete. Right now the only tests that are done +are linters with pre-commit. + Installation ------------ @@ -30,10 +35,10 @@ Remember to commit :code:`.gitmodules`! Modules ------- -- collectd_facts -- ldap_attr -- nginx_facts -- dhparams +- collectd_facts (use the :code:`package_facts` module instead) +- ldap_attr (has been accepted in to the Ansible project) +- nginx_facts (use the :code:`package_facts` module instead) +- dhparams (use the :code:`openssl_dhparams` module instead) Usage ----- @@ -50,11 +55,10 @@ Testing ------- Modules are tested on Ubuntu Precise, Trusty and Xenial and Debian Wheezy, -Jessie and Stretch with Ansible version 2.0.2.0, 2.1.6.0, 2.2.3.0 and 2.3.1.0 -in `TravisCI <https://travis-ci.org/adarnimrod/ansible-modules>`_. To tests -require `Tox <https://tox.readthedocs.io/>`_ and `Docker -<https://docker.com>`_. `Pre-commit <http://pre-commit.com/>`_ is also setup -for this project. +Jessie and Stretch with Ansible version 2.0.2.0, 2.1.6.0, 2.2.3.0 and 2.3.1.0. +The tests require `Tox <https://tox.readthedocs.io/>`_ and `Docker +<https://docker.com>`_. `Pre-commit <http://pre-commit.com/>`_ is also setup for +this project. Author ------ @@ -62,7 +66,7 @@ Author Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website <https://www.shore.co.il/>`_. Patches are welcome via `git send-email <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located -at: https://www.shore.co.il/git/. +at: https://git.shore.co.il/explore/. TODO ---- diff --git a/collectd/collectd_facts b/collectd/collectd_facts index 67151ebbc50df88627a41fa3ec296731c0d01530..5674482256a062adf34c603a6088276ad00fa18f 100755 --- a/collectd/collectd_facts +++ b/collectd/collectd_facts @@ -8,6 +8,6 @@ fail () exit } -which collectd > /dev/null 2>&1 || fail "Can't find collectd executable." +command -v collectd > /dev/null 2>&1 || fail "Can't find collectd executable." collectd -h 2>&1 | sed -n 's/[a-zA-Z ]*\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/{"changed": false, "ansible_facts": {"collectd": {"major":\1, "minor":\2, "patch":\3, "version":"\1.\2.\3"}}}/p' diff --git a/nginx/nginx_facts b/nginx/nginx_facts index 7e1da372c95208ed38d73a2caa99931e65876326..db55dd8257a1da12e9e0126535617a8f1ad19bf6 100755 --- a/nginx/nginx_facts +++ b/nginx/nginx_facts @@ -8,6 +8,6 @@ fail () exit } -which nginx > /dev/null 2>&1 || fail "Can't find nginx executable." +command -v nginx > /dev/null 2>&1 || fail "Can't find nginx executable." nginx -v 2>&1 | sed -n 's/[a-zA-Z :\/]*\([0-9]*\)\.\([0-9]*\)\.\([0-9]\)*.*$/{"changed": false, "ansible_facts": {"nginx": {"major":\1, "minor":\2, "patch":\3, "version":"\1.\2.\3"}}}/gp' diff --git a/tests/collectd.yml b/tests/collectd.yml index 325bdd0b4e5e3790ebf9aa28aa0530eb6f28c8d6..3b3de338ed7c113243a5380e6bf31c27408a3303 100644 --- a/tests/collectd.yml +++ b/tests/collectd.yml @@ -3,7 +3,7 @@ apt: name: collectd-core state: latest - install_recommends: no + install_recommends: false - name: Collectd facts collectd_facts: @@ -16,8 +16,8 @@ - name: Assertions assert: that: - - collectd_facts|changed == False - - collectd.major is number - - collectd.minor is number - - collectd.patch is number - - collectd.version is defined + - collectd_facts|changed == false + - collectd.major is number + - collectd.minor is number + - collectd.patch is number + - collectd.version is defined diff --git a/tests/nginx.yml b/tests/nginx.yml index 946bad7b2fa1a48b4f8e5e37a7875f7b68120012..0ab80a81f3486eba110fb8238a760bc32032564f 100644 --- a/tests/nginx.yml +++ b/tests/nginx.yml @@ -3,7 +3,7 @@ apt: name: nginx-light state: latest - install_recommends: no + install_recommends: false - name: Nginx facts nginx_facts: @@ -16,8 +16,8 @@ - name: Assertions assert: that: - - nginx_facts|changed == False - - nginx.major is number - - nginx.minor is number - - nginx.patch is number - - nginx.version is defined + - nginx_facts|changed == false + - nginx.major is number + - nginx.minor is number + - nginx.patch is number + - nginx.version is defined diff --git a/tests/playbook.yaml b/tests/playbook.yaml index f69f17825f1a02bcc1f47c35130e9da19b96f0e3..90e84a66f0e70b2ea4bb7c1a1ca29736986fbb35 100644 --- a/tests/playbook.yaml +++ b/tests/playbook.yaml @@ -1,8 +1,8 @@ --- - hosts: localhost connection: local - gather_facts: False - become: False + gather_facts: false + become: false tasks: - name: Assertion assert: @@ -15,14 +15,20 @@ # consistency across different versions of Ansible. command: 'docker rm -f ansible_modules_{{ distro }}_{{ release }}' register: docker_rm - failed_when: "docker_rm|failed and 'no such container' not in docker_rm.stderr|lower" + failed_when: |- + docker_rm|failed and 'no such container' not in docker_rm.stderr|lower changed_when: "'no such container' not in docker_rm.stderr|lower" - name: Create Docker container # Use the command module instead of docker/ docker-container for # consistency across different versions of Ansible. - command: 'docker run --detach --name ansible_modules_{{ distro }}_{{ release }} {{ distro }}:{{ release }} tail -f /.dockerenv' - changed_when: True + command: >- + docker run + --detach + --name ansible_modules_{{ distro }}_{{ release }} + {{ distro }}:{{ release }} + tail -f /.dockerenv + changed_when: true - name: Add Docker container to inventory add_host: @@ -32,23 +38,24 @@ groups: containers - hosts: containers - gather_facts: False + gather_facts: false roles: - name: debian-bootstrap post_tasks: - - name: Include test tasks - with_fileglob: '{{ playbook_dir }}/*.yml' - include: '{{ item }}' + - name: Include test tasks + with_fileglob: '{{ playbook_dir }}/*.yml' + include: '{{ item }}' - hosts: localhost connection: local - become: False - gather_facts: False + become: false + gather_facts: false tasks: - name: Remove existing Docker container # Use the command module instead of docker/ docker-container for # consistency across different versions of Ansible. command: 'docker rm -f ansible_modules_{{ distro }}_{{ release }}' register: docker_rm - failed_when: "docker_rm|failed and 'no such container' not in docker_rm.stderr|lower" + failed_when: |- + docker_rm|failed and 'no such container' not in docker_rm.stderr|lower changed_when: "'no such container' not in docker_rm.stderr|lower" diff --git a/tests/ssl.yml b/tests/ssl.yml index 98beeeeac2d08afb9a682bc2af2da24f28ae5d14..6204b73be609ac285039936fae70006ddaff95a1 100644 --- a/tests/ssl.yml +++ b/tests/ssl.yml @@ -3,10 +3,10 @@ apt: name: openssl state: latest - install_recommends: no + install_recommends: false - name: DH params for missing file - ignore_errors: True + ignore_errors: frue dhparams: path: /etc/ssl/dhparams.pem register: missing_dhparams @@ -18,13 +18,13 @@ - name: Assertions assert: that: - - missing_dhparams.bits == 0 - - missing_dhparams|failed == True - - missing_dhparams|changed == False + - missing_dhparams.bits == 0 + - missing_dhparams|failed == true + - missing_dhparams|changed == false - name: Generate DH params command: openssl dhparam -out /etc/ssl/dhparams.pem 2048 - changed_when: True + changed_when: true - name: DH params for existing file dhparams: @@ -38,7 +38,7 @@ - name: Assertions assert: that: - - existing_dhparams.bits == 2048 - - existing_dhparams|failed == False - - existing_dhparams|changed == False - - existing_dhparams.path == '/etc/ssl/dhparams.pem' + - existing_dhparams.bits == 2048 + - existing_dhparams|failed == false + - existing_dhparams|changed == false + - existing_dhparams.path == '/etc/ssl/dhparams.pem'