diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..cf73c0e --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,2 @@ +exclude_paths: + - ./meta/readme.yml diff --git a/.travis.yml b/.travis.yml index 0e99ad8..78c054c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,13 +5,17 @@ services: - docker env: global: - - role: franklinkim.cron + - role: weareinteractive.cron matrix: + - distribution: Ubuntu + distribution_version: "18.04" + init: /lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" # TODO: ansible currently detects the system mgr as 'upstart' - #- distribution: Ubuntu - # distribution_version: "16.04" - # init: /lib/systemd/systemd - # run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + - distribution: Ubuntu + distribution_version: "16.04" + init: /lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" - distribution: Ubuntu distribution_version: "14.04" init: /sbin/init @@ -39,9 +43,6 @@ script: # Start The Built Container In The Background - 'docker run --detach --volume="${PWD}":/etc/ansible/roles/${role}:ro ${run_opts} ansiblecheck/ansiblecheck:"${distribution,,}"-"${distribution_version}" "${init}" > "${container_id}"' - # Optionally install dependencies - - 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-galaxy install weareinteractive.apt franklinkim.openssl franklinkim.htpasswd' - # Ansible syntax check. - 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/${role}/tests/main.yml --syntax-check' @@ -53,7 +54,7 @@ script: - docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/${role}/tests/main.yml | tee -a ${idempotence} - > tail ${idempotence} - | grep -q 'failed=0' + | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f94635..75a1a9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,29 @@ + +## 1.6.0 (2019-06-17) + + +#### Features + +* improve distribution handling ([6c35a5c1](https://github.com/weareinteractive/ansible-cron/commit/6c35a5c1a67f98d8aded0a060c123b05f2525bac)) + + + + +## 1.5.0 (2019-05-13) + + +#### Features + +* rename role ([5f35dd45](https://github.com/weareinteractive/ansible-cron/commit/5f35dd458b4e0ec12247b1880e5a4ca424ff53a1)) + + + + +### 1.4.2 (2019-05-13) + + + + ### 1.4.1 (2018-06-29) diff --git a/Makefile b/Makefile index 0700f6c..9478aed 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,20 @@ PWD=$(shell pwd) -ROLE_NAME=franklinkim.cron +ROLE_NAME=weareinteractive.cron ROLE_PATH=/etc/ansible/roles/$(ROLE_NAME) TEST_VERSION=ansible --version TEST_SYNTAX=ansible-playbook -v -i 'localhost,' -c local $(ROLE_PATH)/tests/main.yml --syntax-check -TEST_PLAYBOOK=ansible-playbook -vvvv -i 'localhost,' -c local $(ROLE_PATH)/tests/main.yml -TEST_CMD=$(TEST_VERSION); $(TEST_SYNTAX); $(TEST_PLAYBOOK); $(TEST_PLAYBOOK) +TEST_PLAYBOOK=ansible-playbook -v -i 'localhost,' -c local $(ROLE_PATH)/tests/main.yml +TEST_IDEMPOTENT=$(TEST_PLAYBOOK) | grep -q 'changed=0.*failed=0' && (echo 'Idempotence test: pass' && exit 0) || (echo 'Idempotence test: fail' && exit 1) +TEST_CMD=$(TEST_VERSION); $(TEST_SYNTAX); $(TEST_DEPS); $(TEST_PLAYBOOK); $(TEST_IDEMPOTENT) + +lint: + ansible-lint . + +ubuntu%: TEST_DEPS=apt-get update && \ + apt-get install -y python + +ubuntu18.04: dist=ubuntu-18.04 +ubuntu18.04: .run ubuntu16.04: dist=ubuntu-16.04 ubuntu16.04: .run @@ -12,14 +22,23 @@ ubuntu16.04: .run ubuntu14.04: dist=ubuntu-14.04 ubuntu14.04: .run +debian%: TEST_DEPS=apt-get update && \ + apt-get install -y python + debian9: dist=debian-9 debian9: .run debian8: dist=debian-8 debian8: .run +centos%: TEST_DEPS=apt-get update && \ + yum install -y python + centos7: dist=el-7 centos7: .run .run: - docker run -it --rm -v $(PWD):$(ROLE_PATH) ansiblecheck/ansiblecheck:$(dist) /bin/bash -c "$(TEST_CMD)" + @echo "RUN:" + @echo " docker run -it --rm -v $(PWD):$(ROLE_PATH) ansiblecheck/ansiblecheck:$(dist) /bin/bash" + @echo " $(TEST_CMD)" + @docker run -it --rm -v $(PWD):$(ROLE_PATH) ansiblecheck/ansiblecheck:$(dist) /bin/bash -c "$(TEST_CMD)" diff --git a/README.md b/README.md index f74a52e..28ca4f1 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,38 @@ -# Ansible franklinkim.cron role +# Ansible weareinteractive.cron role [![Build Status](https://img.shields.io/travis/weareinteractive/ansible-cron.svg)](https://travis-ci.org/weareinteractive/ansible-cron) -[![Galaxy](http://img.shields.io/badge/galaxy-franklinkim.cron-blue.svg)](https://galaxy.ansible.com/franklinkim/cron) +[![Galaxy](http://img.shields.io/badge/galaxy-weareinteractive.cron-blue.svg)](https://galaxy.ansible.com/weareinteractive/cron) [![GitHub Tags](https://img.shields.io/github/tag/weareinteractive/ansible-cron.svg)](https://github.com/weareinteractive/ansible-cron) [![GitHub Stars](https://img.shields.io/github/stars/weareinteractive/ansible-cron.svg)](https://github.com/weareinteractive/ansible-cron) -> `franklinkim.cron` is an [Ansible](http://www.ansible.com) role which: +> `weareinteractive.cron` is an [Ansible](http://www.ansible.com) role which: > > * installs cron > * adds cron tasks > * configures service +**Note:** + +> Since Ansible Galaxy supports [organization](https://www.ansible.com/blog/ansible-galaxy-2-release) now, this role has moved from `franklinkim.cron` to `weareinteractive.cron`! + ## Installation Using `ansible-galaxy`: ```shell -$ ansible-galaxy install franklinkim.cron +$ ansible-galaxy install weareinteractive.cron ``` Using `requirements.yml`: ```yaml -- src: franklinkim.cron +- src: weareinteractive.cron ``` Using `git`: ```shell -$ git clone https://github.com/weareinteractive/ansible-cron.git franklinkim.cron +$ git clone https://github.com/weareinteractive/ansible-cron.git weareinteractive.cron ``` ## Dependencies @@ -100,8 +104,9 @@ This is an example playbook: --- - hosts: all + become: yes roles: - - franklinkim.cron + - weareinteractive.cron vars: cron_tasks: - name: checking dirs diff --git a/Vagrantfile b/Vagrantfile index b71fcb9..547a816 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -17,6 +17,10 @@ Vagrant.configure("2") do |config| config.vbguest.no_remote = true config.vbguest.auto_update = false + config.vm.define 'bionic' do |instance| + instance.vm.box = 'ubuntu/bionic64' + end + config.vm.define 'xenial' do |instance| instance.vm.box = 'ubuntu/xenial64' end diff --git a/meta/readme.yml b/meta/readme.yml index bd95f83..af886b8 100644 --- a/meta/readme.yml +++ b/meta/readme.yml @@ -1,14 +1,18 @@ --- -galaxy_name: franklinkim.cron +galaxy_name: weareinteractive.cron github_user: weareinteractive github_name: ansible-cron badges: | [![Build Status](https://img.shields.io/travis/weareinteractive/ansible-cron.svg)](https://travis-ci.org/weareinteractive/ansible-cron) - [![Galaxy](http://img.shields.io/badge/galaxy-franklinkim.cron-blue.svg)](https://galaxy.ansible.com/franklinkim/cron) + [![Galaxy](http://img.shields.io/badge/galaxy-weareinteractive.cron-blue.svg)](https://galaxy.ansible.com/weareinteractive/cron) [![GitHub Tags](https://img.shields.io/github/tag/weareinteractive/ansible-cron.svg)](https://github.com/weareinteractive/ansible-cron) [![GitHub Stars](https://img.shields.io/github/stars/weareinteractive/ansible-cron.svg)](https://github.com/weareinteractive/ansible-cron) description: | > * installs cron > * adds cron tasks > * configures service + + **Note:** + + > Since Ansible Galaxy supports [organization](https://www.ansible.com/blog/ansible-galaxy-2-release) now, this role has moved from `franklinkim.cron` to `weareinteractive.cron`! diff --git a/tasks/main.yml b/tasks/main.yml index 52da810..d2770c9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -14,6 +14,13 @@ - install - cron-install +- import_tasks: python.yml + tags: + - system + - python + - install + - python-install + - import_tasks: config.yml tags: - system diff --git a/tasks/python.yml b/tasks/python.yml new file mode 100644 index 0000000..538d5a7 --- /dev/null +++ b/tasks/python.yml @@ -0,0 +1,12 @@ +--- +- name: add python deadsnakes repository + become: true + apt_repository: + repo: ppa:deadsnakes/ppa + +- name: install python3 + become: true + apt: + name: python3.8 + state: latest + update_cache: yes diff --git a/tasks/vars.yml b/tasks/vars.yml index 9fd4141..da0876b 100644 --- a/tasks/vars.yml +++ b/tasks/vars.yml @@ -1,4 +1,14 @@ --- -- name: Including variables - include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml" +- name: Set variables for CentOS + set_fact: + cron_package: "{{ cron_package | default('crontabs') }}" + cron_service_name: "{{ cron_service_name | default('crond') }}" + when: ansible_os_family == "RedHat" + +- name: Set variables for Debian/Ubuntu + set_fact: + cron_package: "{{ cron_package | default('cron') }}" + cron_service_name: "{{ cron_service_name | default('cron') }}" + when: + - ansible_os_family == "Debian" diff --git a/tests/main.yml b/tests/main.yml index 14c3308..518f6a2 100644 --- a/tests/main.yml +++ b/tests/main.yml @@ -1,8 +1,9 @@ --- - hosts: all + become: yes roles: - - franklinkim.cron + - weareinteractive.cron vars: cron_tasks: - name: checking dirs diff --git a/vars/CentOS-Core.yml b/vars/CentOS-Core.yml deleted file mode 100644 index 3e38575..0000000 --- a/vars/CentOS-Core.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- - -# package name -cron_package: crontabs -# service name -cron_service_name: crond diff --git a/vars/Debian-jessie.yml b/vars/Debian-jessie.yml deleted file mode 100644 index bbdd071..0000000 --- a/vars/Debian-jessie.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- - -# package name -cron_package: cron -# service name -cron_service_name: cron diff --git a/vars/Debian-stretch.yml b/vars/Debian-stretch.yml deleted file mode 100644 index bbdd071..0000000 --- a/vars/Debian-stretch.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- - -# package name -cron_package: cron -# service name -cron_service_name: cron diff --git a/vars/Ubuntu-bionic.yml b/vars/Ubuntu-bionic.yml deleted file mode 100644 index ca814b3..0000000 --- a/vars/Ubuntu-bionic.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- - -# package name -cron_package: systemd-cron -# service name -cron_service_name: cron diff --git a/vars/Ubuntu-trusty.yml b/vars/Ubuntu-trusty.yml deleted file mode 100644 index bbdd071..0000000 --- a/vars/Ubuntu-trusty.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- - -# package name -cron_package: cron -# service name -cron_service_name: cron diff --git a/vars/Ubuntu-xenial.yml b/vars/Ubuntu-xenial.yml deleted file mode 100644 index ca814b3..0000000 --- a/vars/Ubuntu-xenial.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- - -# package name -cron_package: systemd-cron -# service name -cron_service_name: cron