diff --git a/.drone.jsonnet b/.drone.jsonnet index 036d7c3..d2dfd21 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -112,6 +112,7 @@ local PipelineDocumentation = { }, depends_on: [ 'testing-centos7', + 'testing-centos8', ], }; @@ -150,6 +151,7 @@ local PipelineNotification = { [ PipelineLinting, PipelineDeployment(scenario='centos7'), + PipelineDeployment(scenario='centos8'), PipelineDocumentation, PipelineNotification, ] diff --git a/.drone.yml b/.drone.yml index 2bc0e2e..ba4eedf 100644 --- a/.drone.yml +++ b/.drone.yml @@ -53,6 +53,41 @@ trigger: depends_on: - linting +--- +kind: pipeline +name: testing-centos8 + +platform: + os: linux + arch: amd64 + +concurrency: + limit: 1 + +workspace: + base: /drone/src + path: xoxys.lvm + +steps: +- name: ansible-molecule + image: xoxys/molecule:latest + commands: + - molecule test -scentos8 + environment: + DO_API_KEY: + from_secret: do_api_key + MOLECULE_CUSTOM_FILTERS_REPO: https://gitea.rknet.org/ansible/custom_filters + MOLECULE_CUSTOM_MODULES_REPO: https://gitea.rknet.org/ansible/custom_modules + USER: root + +trigger: + ref: + - refs/heads/master + - refs/tags/** + +depends_on: +- linting + --- kind: pipeline name: documentation @@ -108,6 +143,7 @@ trigger: depends_on: - testing-centos7 +- testing-centos8 --- kind: pipeline @@ -147,6 +183,6 @@ depends_on: --- kind: signature -hmac: 3528f8e1888582a0f583e11b6c8327d75ba99f19c46fc54b3a47578b0592564a +hmac: a7b145bd760afa7c69c180fdf11ce4d595e8692fe7f5346da66ef966a571faad ... diff --git a/meta/main.yml b/meta/main.yml index df2e084..1621cff 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -17,6 +17,7 @@ galaxy_info: - name: EL versions: - 7 + - 8 galaxy_tags: - storage - lvm diff --git a/molecule/centos7/playbook.yml b/molecule/centos7/playbook.yml index 74033bb..20e0d39 100644 --- a/molecule/centos7/playbook.yml +++ b/molecule/centos7/playbook.yml @@ -11,7 +11,7 @@ size: 1g resizefs: True mountpoint: /mnt/data - state: present + state: mounted roles: - role: xoxys.lvm diff --git a/molecule/centos8/create.yml b/molecule/centos8/create.yml new file mode 100644 index 0000000..a9dae89 --- /dev/null +++ b/molecule/centos8/create.yml @@ -0,0 +1,106 @@ +--- +- name: Create + hosts: localhost + connection: local + gather_facts: false + no_log: "{{ molecule_no_log }}" + vars: + ssh_user: root + ssh_port: 22 + + keypair_name: molecule_key + keypair_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key" + tasks: + - name: Create local keypair + user: + name: "{{ lookup('env', 'USER') }}" + generate_ssh_key: true + ssh_key_file: "{{ keypair_path }}" + register: local_keypair + + - name: Create remote keypair + digital_ocean_sshkey: + name: "{{ keypair_name }}" + ssh_pub_key: "{{ local_keypair.ssh_public_key }}" + state: present + register: remote_keypair + + - name: Create molecule instance(s) + digital_ocean_droplet: + name: "{{ item.name }}" + unique_name: true + region: "{{ item.region_id }}" + image: "{{ item.image_id }}" + size: "{{ item.size_id }}" + ssh_keys: "{{ remote_keypair.data.ssh_key.id }}" + wait: true + wait_timeout: 300 + state: present + register: server + loop: "{{ molecule_yml.platforms }}" + async: 7200 + poll: 0 + + - name: Wait for instance(s) creation to complete + async_status: + jid: "{{ item.ansible_job_id }}" + register: digitalocean_jobs + until: digitalocean_jobs.finished + retries: 300 + loop: "{{ server.results }}" + + - name: Create new block storage + digital_ocean_block_storage: + state: present + command: create + region: "{{ item.data.droplet.region.slug }}" + block_size: 2 + volume_name: "{{ item.data.droplet.name }}-blk" + loop: "{{ digitalocean_jobs.results }}" + + - name: Attach block storage to instance + digital_ocean_block_storage: + state: present + command: attach + volume_name: "{{ item.data.droplet.name }}-blk" + region: "{{ item.data.droplet.region.slug }}" + droplet_id: "{{ item.data.droplet.id }}" + loop: "{{ digitalocean_jobs.results }}" + + # Mandatory configuration for Molecule to function. + + - name: Populate instance config dict + set_fact: + instance_conf_dict: { + 'instance': "{{ item.data.droplet.name }}", + 'address': "{{ item.data.ip_address }}", + 'user': "{{ ssh_user }}", + 'port': "{{ ssh_port }}", + 'identity_file': "{{ keypair_path }}", + 'droplet_id': "{{ item.data.droplet.id }}", + 'droplet_region': "{{ item.data.droplet.region.slug }}", + 'ssh_key_id': "{{ remote_keypair.data.ssh_key.id }}", + } + loop: "{{ digitalocean_jobs.results }}" + register: instance_config_dict + when: server.changed | bool + + - name: Convert instance config dict to a list + set_fact: + instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}" + when: server.changed | bool + + - name: Dump instance config + copy: + content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}" + dest: "{{ molecule_instance_config }}" + when: server.changed | bool + + - name: Wait for SSH + wait_for: + port: "{{ ssh_port }}" + host: "{{ item.address }}" + search_regex: SSH + delay: 10 + timeout: 320 + loop: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}" diff --git a/molecule/centos8/destroy.yml b/molecule/centos8/destroy.yml new file mode 100644 index 0000000..e6c36c1 --- /dev/null +++ b/molecule/centos8/destroy.yml @@ -0,0 +1,71 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: false + no_log: "{{ molecule_no_log }}" + tasks: + - block: + - name: Populate instance config + set_fact: + instance_conf: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}" + skip_instances: false + rescue: + - name: Populate instance config when file missing + set_fact: + instance_conf: {} + skip_instances: true + + - name: Detach block storage from instance + digital_ocean_block_storage: + state: absent + command: attach + volume_name: "{{ item.instance }}-blk" + region: "{{ item.droplet_region }}" + droplet_id: "{{ item.droplet_id }}" + loop: "{{ instance_conf | flatten(levels=1) }}" + + - name: Destroy molecule instance(s) + digital_ocean_droplet: + name: "{{ item.instance }}" + id: "{{ item.droplet_id }}" + state: absent + register: server + loop: "{{ instance_conf | flatten(levels=1) }}" + when: not skip_instances + async: 7200 + poll: 0 + + - name: Wait for instance(s) deletion to complete + async_status: + jid: "{{ item.ansible_job_id }}" + register: digitalocean_jobs + until: digitalocean_jobs.finished + retries: 300 + loop: "{{ server.results }}" + + - name: Delete block storage + digital_ocean_block_storage: + state: absent + command: create + region: "{{ item.droplet_region }}" + volume_name: "{{ item.instance }}-blk" + loop: "{{ instance_conf | flatten(levels=1) }}" + + - name: Delete remote keypair + digital_ocean_sshkey: + fingerprint: "{{ item.ssh_key_id }}" + state: absent + loop: "{{ instance_conf | flatten(levels=1) }}" + + # Mandatory configuration for Molecule to function. + + - name: Populate instance config + set_fact: + instance_conf: {} + + - name: Dump instance config + copy: + content: "{{ instance_conf | molecule_to_yaml | molecule_header }}" + dest: "{{ molecule_instance_config }}" + when: server.changed | bool diff --git a/molecule/centos8/molecule.yml b/molecule/centos8/molecule.yml new file mode 100644 index 0000000..dc09aa3 --- /dev/null +++ b/molecule/centos8/molecule.yml @@ -0,0 +1,22 @@ +--- +dependency: + name: galaxy +driver: + name: digitalocean +platforms: + - name: centos8-lvm + region_id: fra1 + image_id: centos-8-x64 + size_id: s-1vcpu-1gb +lint: + name: yamllint + enabled: False +provisioner: + name: ansible + lint: + name: ansible-lint + enabled: False +verifier: + name: testinfra + lint: + name: flake8 diff --git a/molecule/centos8/playbook.yml b/molecule/centos8/playbook.yml new file mode 100644 index 0000000..20e0d39 --- /dev/null +++ b/molecule/centos8/playbook.yml @@ -0,0 +1,17 @@ +--- +- name: Converge + hosts: all + vars: + lvm_volumes: + - name: lv_test + group: vg_test + disks: + - /dev/sda + fstype: ext4 + size: 1g + resizefs: True + mountpoint: /mnt/data + state: mounted + + roles: + - role: xoxys.lvm diff --git a/molecule/centos8/prepare.yml b/molecule/centos8/prepare.yml new file mode 100644 index 0000000..4b18d48 --- /dev/null +++ b/molecule/centos8/prepare.yml @@ -0,0 +1,9 @@ +--- +- name: Prepare + hosts: all + gather_facts: false + tasks: + - name: Install python for Ansible + raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal) + become: true + changed_when: false diff --git a/molecule/centos8/tests/test_default.py b/molecule/centos8/tests/test_default.py new file mode 100644 index 0000000..e3776d5 --- /dev/null +++ b/molecule/centos8/tests/test_default.py @@ -0,0 +1,20 @@ +import os + +import testinfra.utils.ansible_runner + +import warnings +warnings.filterwarnings("ignore", category=DeprecationWarning) + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_lvm_in_fstab(host): + fstab = host.file("/etc/fstab") + assert fstab.contains("/dev/mapper/vg_test-lv_test") + + +def test_lvm_mounted(host): + mount = host.check_output("mount") + lvm = "/dev/mapper/vg_test-lv_test on /mnt/data type ext4" + assert lvm in mount diff --git a/molecule/default b/molecule/default index 2fdf3e8..575742e 120000 --- a/molecule/default +++ b/molecule/default @@ -1 +1 @@ -centos7 \ No newline at end of file +centos8 \ No newline at end of file