diff --git a/.drone.jsonnet b/.drone.jsonnet new file mode 100644 index 0000000..7ba520e --- /dev/null +++ b/.drone.jsonnet @@ -0,0 +1,72 @@ +// Distros to Test on ;) +local distros = ['centos7', + 'centos8', + 'rockylinux8', + 'debian10', + 'debian11']; + + +/* Configuration of DIND */ +local docker_service() = + { + name: 'docker', + image: 'docker:dind', + privileged: true, + volumes: [{ name: 'dockersock', path: '/var/run' },], + }; + +local email_notification() = + { + name: 'notify by email', + image: 'drillster/drone-email', + settings: + { host: 'mail.guise.net.nz', + username: + { from_secret: 'EMAIL_USER' }, + password: + { from_secret: 'EMAIL_PASS' }, + from: 'drone@guise.net.nz' + }, + when: + { status: [ 'changed', 'failure' ] }, + }; + +local test_distro(distribution) = + { + name: 'Test on %(distribution)s' % { distribution: distribution }, + volumes: [{ name: 'dockersock', path: '/var/run' },], + image: 'guisea/ansible-molecule:latest', + commands: [ + 'sleep 10', // give docker enough time to start + 'mkdir ${DRONE_REPO_NAME}', + 'rsync -a . ${DRONE_REPO_NAME} --exclude ${DRONE_REPO_NAME}', + 'cd ${DRONE_REPO_NAME}', + 'molecule test' + ], + environment: + { MOLECULE_DISTRO: '%(distribution)s' % { distribution: distribution } + }, + }; + +local gen_pipeline(distro) = + {kind: 'pipeline', + type: 'docker', + name: 'Test on %(distro)s' % { distro: distro }, + steps: [ + test_distro(distro), + email_notification()], + services: [ + docker_service(), + ], + volumes: + [{ + name: 'dockersock', + temp: {}, + },], + }; + +// Generate the output +[ + gen_pipeline(distro) + for distro in distros +] \ No newline at end of file diff --git a/.drone.yml b/.drone.yml index b087737..038d3ae 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,83 +1,164 @@ --- kind: pipeline -name: centos7 - +name: Test on centos7 services: -- name: docker - image: docker:dind +- image: docker:dind + name: docker privileged: true volumes: - name: dockersock path: /var/run - -volumes: -- name: dockersock - temp: {} - steps: -- name: Test with Molecule centos7 - image: guisea/ansible-molecule:latest - volumes: - - name: dockersock - path: /var/run - commands: - - sleep 10 # give docker enough time to start +- commands: + - sleep 10 - mkdir ${DRONE_REPO_NAME} - rsync -a . ${DRONE_REPO_NAME} --exclude ${DRONE_REPO_NAME} - cd ${DRONE_REPO_NAME} - molecule test environment: MOLECULE_DISTRO: centos7 -- name: notify by email - image: drillster/drone-email + image: guisea/ansible-molecule:latest + name: Test on centos7 + volumes: + - name: dockersock + path: /var/run +- image: drillster/drone-email + name: notify by email settings: + from: drone@guise.net.nz host: mail.guise.net.nz - username: - from_secret: EMAIL_USER password: from_secret: EMAIL_PASS - from: drone@guise.net.nz + username: + from_secret: EMAIL_USER when: - status: [ changed, failure ] - + status: + - changed + - failure +type: docker +volumes: +- name: dockersock + temp: {} --- kind: pipeline -name: debian10 - +name: Test on centos8 services: -- name: docker - image: docker:dind +- image: docker:dind + name: docker privileged: true volumes: - name: dockersock path: /var/run - -volumes: -- name: dockersock - temp: {} - steps: -- name: Test with Molecule debian10 +- commands: + - sleep 10 + - mkdir ${DRONE_REPO_NAME} + - rsync -a . ${DRONE_REPO_NAME} --exclude ${DRONE_REPO_NAME} + - cd ${DRONE_REPO_NAME} + - molecule test + environment: + MOLECULE_DISTRO: centos8 image: guisea/ansible-molecule:latest + name: Test on centos8 volumes: - name: dockersock path: /var/run - commands: - - sleep 10 # give docker enough time to start +- image: drillster/drone-email + name: notify by email + settings: + from: drone@guise.net.nz + host: mail.guise.net.nz + password: + from_secret: EMAIL_PASS + username: + from_secret: EMAIL_USER + when: + status: + - changed + - failure +type: docker +volumes: +- name: dockersock + temp: {} +--- +kind: pipeline +name: Test on debian10 +services: +- image: docker:dind + name: docker + privileged: true + volumes: + - name: dockersock + path: /var/run +steps: +- commands: + - sleep 10 - mkdir ${DRONE_REPO_NAME} - rsync -a . ${DRONE_REPO_NAME} --exclude ${DRONE_REPO_NAME} - cd ${DRONE_REPO_NAME} - molecule test environment: MOLECULE_DISTRO: debian10 -- name: notify by email - image: drillster/drone-email + image: guisea/ansible-molecule:latest + name: Test on debian10 + volumes: + - name: dockersock + path: /var/run +- image: drillster/drone-email + name: notify by email settings: + from: drone@guise.net.nz host: mail.guise.net.nz - username: - from_secret: EMAIL_USER password: from_secret: EMAIL_PASS - from: drone@guise.net.nz + username: + from_secret: EMAIL_USER when: - status: [ changed, failure ] + status: + - changed + - failure +type: docker +volumes: +- name: dockersock + temp: {} +--- +kind: pipeline +name: Test on debian11 +services: +- image: docker:dind + name: docker + privileged: true + volumes: + - name: dockersock + path: /var/run +steps: +- commands: + - sleep 10 + - mkdir ${DRONE_REPO_NAME} + - rsync -a . ${DRONE_REPO_NAME} --exclude ${DRONE_REPO_NAME} + - cd ${DRONE_REPO_NAME} + - molecule test + environment: + MOLECULE_DISTRO: debian11 + image: guisea/ansible-molecule:latest + name: Test on debian11 + volumes: + - name: dockersock + path: /var/run +- image: drillster/drone-email + name: notify by email + settings: + from: drone@guise.net.nz + host: mail.guise.net.nz + password: + from_secret: EMAIL_PASS + username: + from_secret: EMAIL_USER + when: + status: + - changed + - failure +type: docker +volumes: +- name: dockersock + temp: {} \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml index 9c1bdd7..a01da50 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,8 +16,6 @@ common_grub_timeout: 5 postfix_configure: false common_packages: - - libselinux-python - - MySQL-python - nano - git - htop diff --git a/tasks/common.yml b/tasks/common.yml new file mode 100644 index 0000000..8f43b50 --- /dev/null +++ b/tasks/common.yml @@ -0,0 +1,5 @@ +--- +- include_tasks: networking.yml +- include_tasks: communication.yml +- include_tasks: grub.yml +- include_tasks: motd.yml \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index ed12d9c..31ef1b3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,9 @@ --- -- include: "{{ ansible_os_family }}.yml" \ No newline at end of file +- name: Include tasks only if one of the files exist, otherwise skip the task + include_tasks: '{{ item }}' + vars: + params: + files: + - '{{ ansible_os_family }}.yml' + - 'common.yml' + loop: "{{ q('first_found', params, errors='ignore') }}" diff --git a/utils.libsonnet b/utils.libsonnet new file mode 100644 index 0000000..51becad --- /dev/null +++ b/utils.libsonnet @@ -0,0 +1,42 @@ +{ +docker_service():: + { + name: 'docker', + image: 'docker:dind', + privileged: true, + volumes: [{ name: 'dockersock', path: '/var/run' },], + }, + +email_notification():: + { + name: 'notify by email', + image: 'drillster/drone-email', + settings: + { host: 'mail.guise.net.nz', + username: + { from_secret: 'EMAIL_USER' }, + password: + { from_secret: 'EMAIL_PASS' }, + from: 'drone@guise.net.nz' + }, + when: + { status: [ 'changed', 'failure' ] }, + }, + +test_distro(distribution):: + { + name: 'Test on %(distribution)s' % { distribution: distribution }, + volumes: [{ name: 'dockersock', path: '/var/run' },], + image: 'guisea/ansible-molecule:latest', + commands: [ + 'sleep 10', // give docker enough time to start + 'mkdir ${DRONE_REPO_NAME}', + 'rsync -a . ${DRONE_REPO_NAME} --exclude ${DRONE_REPO_NAME}', + 'cd ${DRONE_REPO_NAME}', + 'molecule test' + ], + environment: + { MOLECULE_DISTRO: '%(distribution)s' % { distribution: distribution } + }, + }, +}