diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6274aa01b223aa43f1be946e2da2470f5d90e446..233bc80d8f4b0a2ed98f97e33a6269dd6ef0d882 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,35 @@ - repo: https://github.com/pre-commit/pre-commit-hooks - sha: 6dfcb89af3c9b4d172cc2e5a8a2fa0f54615a338 + sha: 7539d8bd1a00a3c1bfd34cdb606d3a6372e83469 hooks: - id: check-added-large-files - id: check-json - id: check-xml - id: check-yaml - id: check-merge-conflict -- repo: https://www.shore.co.il/git/ansible-pre-commit/ - sha: 94b506c144d4e22ebc1deef637a818db13bcaca5 + - id: flake8 + - id: check-symlinks +- repo: https://github.com/adarnimrod/ansible-pre-commit.git + sha: 0fadd691465b97db8992cfc66650f630e433324b hooks: - - id: ansible-pre-commit + - id: ansible-syntax-check + always_run: true + files: tests/playbook.yml + args: + - tests/playbook.yml +- repo: https://github.com/willthames/ansible-lint + sha: 959ab0f525e9abb19cf75f34381015cf33695f61 + hooks: + - id: ansible-lint + always_run: true + files: tests/playbook.yml + args: + - tests/playbook.yml +- repo: local + hooks: + - id: piprot + name: piprot + description: Check up-to-date Python requirements + language: system + entry: piprot --quiet --outdated tests/requirements.txt + files: requirements.txt + always_run: true diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..3d4c7d8d6cc14b65a42fef763027e4430760db66 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +--- +language: python +python: "2.7" +dist: trusty +sudo: false +group: beta +services: [docker] +cache: + - pip + - directories: + - $HOME/.pre-commit + - $HOME/virtualenv + +install: + - pip install -r tests/requirements.txt | cat + - ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles + - molecule dependency + +script: + - pre-commit run --all-files + - molecule test --driver docker + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ + email: false diff --git a/README.rst b/README.rst index 6412e3cdcc8d7873a32b29504b11873dba45f6ea..c1ac43435f755e5463cf1d0e99540b34e1aa13ae 100644 --- a/README.rst +++ b/README.rst @@ -1,13 +1,15 @@ Gitolite -################ +######## -An Ansible role for provisioning gitolite and a readonly cgit web interface -(served by Apache). +.. image:: https://travis-ci.org/adarnimrod/gitolite.svg?branch=master + :target: https://travis-ci.org/adarnimrod/gitolite + +Provision Gitolite and a readonly cgit web interface served by Apache. Requirements ------------ -See :code:`meta/main.yml` and assertions at top of :code:`tasks/main.yml`. +See :code:`meta/main.yml` and assertions at the top of :code:`tasks/main.yml`. Role Variables -------------- @@ -27,17 +29,22 @@ See :code:`tests/playbook.yml`. Testing ------- -To install the dependencies: +Testing requires Python 2.7 and either Docker or Vagrant and Virtualbox. +Install the Python dependencies, dependent roles and roles required for +testing: .. code:: shell + pip install -r tests/requirements.txt ansible-galaxy install git+file://$(pwd),$(git rev-parse --abbrev-ref HEAD) -p .molecule/roles + molecule dependency To run the full test suite: .. code:: shell - molecule test + pre-commit run --all-files + molecule test --platform all License ------- @@ -62,7 +69,6 @@ TODO - Include dependencies in `meta/main.yml` and test. - Log to syslog. - Metrics? -- Rebase on ansible-role-example. - Flush handlers and wait for service to come up. - Add mail alias. - Remove dependency on the common role, use specific roles. diff --git a/ansible.cfg b/ansible.cfg index 10b3da5cfa1edbc2186229872bd129f0e34222c8..2bc7613f4df5ddc0fe0f2719df832ddfff4bfe62 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,6 +1,10 @@ [defaults] +library = library host_key_checking = False retry_files_enabled = False -roles_path = roles:../:../../:.molecule/roles +roles_path = .molecule/roles:.molecule/../roles:../:../../ command_warnings = True deprecation_warnings = True + +[ssh_connection] +pipelining = True diff --git a/defaults/main.yml b/defaults/main.yml index 74d8991bd346dfd9b7cbb98000c32a0c2e9ca739..c32c5343f85b191a3d2b90382636991e0d3b2ac5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,4 @@ --- -# defaults file for ansible-role-gitolite - +# defaults file for gitolite # Content of the SSH public key for the gitolite admin account. gitolite_public_key: diff --git a/handlers/main.yml b/handlers/main.yml index 025b089536a5e7e493c72132fdee83bfd38ea5cf..8ba3f328d7131b587956a990c367ba7a6417cffe 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,2 @@ --- -# handlers file for ansible-role-gitolite +# handlers file for gitolite diff --git a/library/__init__.py b/library/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/meta/main.yml b/meta/main.yml index 48e1013ea379311cf690e521a7ad0604b73e5b32..d654a8a57fe2ab0ab98ce60a31b797b24999c780 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,7 +1,7 @@ --- galaxy_info: author: Nimrod Adar - description: Gitolite installation + description: Provision Gitolite and a readonly cgit web interface served by Apache company: Shore technologies license: MIT min_ansible_version: 2.0 @@ -9,7 +9,11 @@ galaxy_info: - name: Debian versions: - jessie + - name: Ubuntu + versions: + - trusty + - xenial galaxy_tags: [ git, scm, gitolite ] dependencies: -- role: common -- role: apache +- name: adarnimrod.apache + src: adarnimrod.apache diff --git a/molecule.yml b/molecule.yml index 0e6fa4796099a5c1be84f0bdaa1420fb298a35bc..227708afe7720ebbc3c593e4a34de955b98196c7 100644 --- a/molecule.yml +++ b/molecule.yml @@ -1,12 +1,13 @@ --- ansible: - verbose: v + verbose: vv playbook: tests/playbook.yml diff: True + config_file: ../ansible.cfg -molecule: - testinfra_dir: tests - ansible_config_template: ansible.cfg +dependency: + name: galaxy + requirements_file: tests/requirements.yml vagrant: providers: @@ -14,9 +15,15 @@ vagrant: type: virtualbox platforms: - name: openbsd - box: kaorimatz/openbsd-5.9-amd64 + box: kaorimatz/openbsd-6.0-amd64 + - name: jessie + box: debian/jessie64 + - name: trusty + box: ubuntu/trusty64 + - name: xenial + box: ubuntu/xenial64 instances: - - name: ansible-role-example + - name: gitolite options: append_platform_to_hostname: yes raw_config_args: @@ -24,3 +31,37 @@ vagrant: - 'vbguest.auto_update = false' - 'landrush.enabled = false' - 'landrush_ip.override = false' + +docker: + containers: + - name: gitolite-xenial + image: ubuntu + image_version: xenial + command: /sbin/init + cap_add: + - SYS_ADMIN + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup + - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket + environment: + DEBIAN_FRONTEND: noninteractive + container: docker + - name: gitolite-jessie + image: debian + image_version: jessie + command: /sbin/init + cap_add: + - SYS_ADMIN + volume_mounts: + - /sys/fs/cgroup:/sys/fs/cgroup + - /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket + environment: + DEBIAN_FRONTEND: noninteractive + container: docker + - name: gitolite-trusty + image: ubuntu + image_version: trusty + command: /sbin/init + environment: + DEBIAN_FRONTEND: noninteractive + container: docker diff --git a/tasks/cgit.yml b/tasks/cgit.yml index b21b14eb81f16e134241e03c6f77f1c5c396255d..a87fbd9b559e61f750a0b0f49d9fd24303f76aad 100644 --- a/tasks/cgit.yml +++ b/tasks/cgit.yml @@ -1,11 +1,6 @@ --- # tasks file for cgit - -- assert: - that: - - ansible_os_family == 'Debian' - -- name: apt install +- name: APT install cgit apt: name: '{{ item }}' state: present diff --git a/tasks/main.yml b/tasks/main.yml index bc15c290e3710fff527f45548e29e1fe3ba04a89..28f4d5290d94f5a04677a04718cac5135b529bea 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,17 +1,18 @@ --- -# tasks file for ansible-role-gitolite - -- assert: - that: - - gitolite_public_key is defined - - ansible_os_family == 'Debian' +# tasks file for gitolite +- name: Assertions + assert: + that: + - ansible_os_family in ['Debian'] + - ansible_distribution_release in ['xenial', 'trusty', 'jessie'] + - gitolite_public_key is defined - name: APT install with_items: - gitolite3 - curl apt: - name: '{{ item }}' + name: ['curl', 'gitolite3'] state: present update_cache: yes cache_valid_time: 3600 diff --git a/tests/playbook.yml b/tests/playbook.yml index e739a2b8827a164702a059f09277dd60fa516e36..826d80039ec09cb2ae1fd508256081236e174a5e 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,5 +1,20 @@ --- -- hosts: all +- hosts: gitolite-openbsd + gather_facts: false + roles: [adarnimrod.openbsd-bootstrap] + +- hosts: gitolite-xenial gather_facts: false + roles: [adarnimrod.debian-bootstrap] + +- hosts: all + pre_tasks: + - name: Create SSH keypair + local_action: command ssh-keygen -t rsa -N '' -f files/id_rsa + run_once: True + become: False + args: + creates: files/id_rsa roles: - - role: ansible-role-example + - role: gitolite + gitolite_public_key: '{{ lookup("file", "id_rsa.pub") }}' diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..114b3c96850994426859efd43abc9e7a75bfdd81 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,8 @@ +ansible==2.2.0.0 +testinfra==1.4.4 +molecule==1.15.0 +ansible-lint==3.4.5 +pre-commit==0.9.3 +piprot==0.9.7 +python-vagrant==0.5.14 +docker-py==1.10.6 diff --git a/tests/requirements.yml b/tests/requirements.yml new file mode 100644 index 0000000000000000000000000000000000000000..cdc294cd67e8c5b70eed5178580e6edde25e10bb --- /dev/null +++ b/tests/requirements.yml @@ -0,0 +1,3 @@ +--- +- src: adarnimrod.openbsd-bootstrap +- src: adarnimrod.debian-bootstrap diff --git a/tests/test_example.py b/tests/test_example.py index a38c7bad4a16b5cd6a5e071ede073a10c7694154..aaea50030b9784f0528df9b936cf1903d3af5994 100644 --- a/tests/test_example.py +++ b/tests/test_example.py @@ -1,6 +1,12 @@ +from testinfra.utils.ansible_runner import AnsibleRunner + +testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all') + + def test_example(Command): assert Command('uname').rc == 0 + def test_root(Command, Sudo): with Sudo(): - assert Command('whoami').stdout == 'root' + assert Command('whoami').stdout.strip() == 'root' diff --git a/vars/main.yml b/vars/main.yml index 7d75b93074e37aa91a4a9696627c936f5a90d0fa..19f6d648c49f511c1b31420f03a31b2ddeba684b 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -# vars file for ansible-role-gitolite +# vars file for gitolite