diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a275ffb8a52743691cc5aa40ae8ba0f11e475cf8..062343e00ce87a63c8455dacb18bca648ceb0bff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,6 +12,15 @@ default: - source /opt/molecule/bin/activate - ansible --version - molecule --version + after_script: + - source /opt/molecule/bin/activate + - molecule destroy --scenario-name ${SCENARIO} + +variables: + SCENARIO: "default" + ANSIBLE_VAULT_PASSWORD_FILE: "${CI_PROJECT_DIR}/molecule/${SCENARIO}/../../../lza_iesample.pass" + ANSIBLE_FORCE_COLOR: 'true' + PY_COLORS: '1' test-job: stage: test @@ -19,15 +28,18 @@ test-job: - "shell" script: # make sure that Ansible Vaults are present and can be decrypted - - echo "${VAULT_IESAMPLE}" > ../lza_iesample.pass - - export ANSIBLE_VAULT_PASSWORD_FILE=../lza_iesample.pass + - echo "${VAULT_IESAMPLE}" > ${ANSIBLE_VAULT_PASSWORD_FILE} + - export ANSIBLE_VAULT_PASSWORD_FILE=${ANSIBLE_VAULT_PASSWORD_FILE} - rm -rf ../ansible_vaults/ - git clone https://gitlab+deploy-token-25:${VAULT_ACCESS_TOKEN}@git.slub-dresden.de/slub-referat-2-3/ansible_vaults.git ../ansible_vaults/; \ # run Molecule tests - - molecule syntax --scenario-name default - - molecule lint --scenario-name default - - molecule create --scenario-name default - - molecule converge --scenario-name default - - molecule idempotence --scenario-name default - # - molecule verify --scenario-name default - - molecule destroy --scenario-name default + - molecule syntax --scenario-name ${SCENARIO} + # We cannot use `molecule lint` anymore because: + # - https://github.com/ansible-community/molecule/pull/3802 "Remove lint command" + # - https://github.com/ansible-community/molecule/discussions/3825#discussioncomment-4908366 + - yamllint --strict --format colored ./ + - ansible-lint --format full --profile production --strict --force-color ./ + - molecule create --scenario-name ${SCENARIO} + - molecule converge --scenario-name ${SCENARIO} + - molecule idempotence --scenario-name ${SCENARIO} + # - molecule verify --scenario-name ${SCENARIO} diff --git a/molecule/resources/playbooks/prepare.yml b/molecule/resources/playbooks/prepare.yml index 77c4fdfdea16d96375a06ee059bd1226a2132a6c..b15367f5f1e116e022d1cb1f0e947c54ff4faced 100644 --- a/molecule/resources/playbooks/prepare.yml +++ b/molecule/resources/playbooks/prepare.yml @@ -1,30 +1,108 @@ --- - name: Prepare hosts: "*" - tasks: - - name: install GPG - ansible.builtin.apt: - name: "gnupg" - state: latest - update_cache: true - become: true - - name: add non-free repos to be able to install libmath-random-perl from Debian public repo - ansible.builtin.replace: - path: "/etc/apt/sources.list" - regexp: '^(.*) main$' - replace: '\g<1> main non-free' - become: true - - name: add GPG key for SLUB Debian repository - ansible.builtin.apt_key: - # url: "https://sdvdebianrepo.slub-dresden.de/deb-repository/pub.gpg.key" - url: "http://bdv141.slub-dresden.de/deb-repository/pub.gpg.key" - state: present + pre_tasks: + - name: configure additional package repositories for Debian + when: ansible_os_family == "Debian" + block: + - name: install GPG + ansible.builtin.apt: + name: "gnupg" + state: latest + update_cache: true + become: true + - name: add GPG key for SLUB Debian repository + ansible.builtin.apt_key: + url: "{{ item }}" + state: absent + loop: + - "http://bdv141.slub-dresden.de/deb-repository/pub.gpg.key" + - "https://sdvdebianrepo.slub-dresden.de/deb-repository/pub.gpg.key" + - name: add repo URL to sources.list + ansible.builtin.apt_repository: + repo: "{{ item }}" + state: absent + loop: + - "deb http://bdv141.slub-dresden.de/deb-repository lza-testing main" + - "deb https://sdvdebianrepo.slub-dresden.de/deb-repository bullseye main" + - name: modify package repo config + ansible.builtin.deb822_repository: + architectures: "amd64" + components: "{{ item.components | default('main') }}" + enabled: "{{ item.enabled | default(true) }}" + name: "{{ item.name }}" + pdiffs: true + signed_by: "{{ item.signed_by }}" + suites: "{{ item.suites | default(ansible_lsb.codename) }}" + uris: "{{ item.uris }}" + loop: + # PC @steidl with local Debian repo for SubAp tests + # - name: "bdv141" + # signed_by: "http://bdv141.slub-dresden.de/deb-repository/pub.gpg.key" + # suites: "lza-testing" + # uris: "http://bdv141.slub-dresden.de/deb-repository" + # on-prem Debian Repo + - name: "slub" + signed_by: "https://sdvdebianrepo.slub-dresden.de/deb-repository/pub.gpg.key" + uris: "https://sdvdebianrepo.slub-dresden.de/deb-repository" + # add non-free repos to be able to install libmath-random-perl from official Debian public repo + - name: "debian" + components: ["main", "non-free"] + signed_by: "/usr/share/keyrings/debian-archive-keyring.gpg" + suites: ["{{ ansible_lsb.codename }}", "{{ ansible_lsb.codename }}-updates"] + uris: "http://deb.debian.org/debian" + notify: update package cache + become: true + + - name: configure additional package repositories for RedHat + when: ansible_os_family == "RedHat" + block: + - name: add custom repositories + ansible.builtin.yum_repository: + name: "{{ item.name }}" + description: "{{ item.description }}" + baseurl: "{{ item.baseurl }}" + gpgcheck: "{{ item.gpgcheck | default('true') }}" + gpgkey: "{{ item.gpgkey | default(omit) }}" + loop: + - name: "epel" + description: EPEL YUM repo + baseurl: "https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/x86_64/" + gpgkey: "https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}" + - name: "slub" + description: SLUB YUM repo + baseurl: "https://sdvrhelrepo.slub-dresden.de/" + gpgcheck: "false" + notify: update package cache + - name: remove legacy repo configuration to avoid double configuration for SLUB repo + ansible.builtin.file: + path: "/etc/yum.repos.d/SLUB.repo" + state: absent + notify: update package cache + + # Ansible roles can install a multitude of firewall rules, some of which + # will lock us out of our Molecule test VM if we don't take precautions. + # As Molecule itself uses SSH just like Ansible, we need to open port + # tcp/22 to the private /24 subnet that Vagrant uses when provisioning the + # VM. As we don't know for sure what the address for this subnet is and it + # can change across servers/platforms, we gather this information + # dynamically and filter it through `ipaddr` to get the address of the + # whole subnet. The rule is inserted right on top of the list to make sure + # we always get access. + - name: add firewall rule to allow access from Molecule host into testing VM + ansible.builtin.iptables: + action: insert + rule_num: 1 + chain: INPUT + comment: "molecule access" + jump: "ACCEPT" + protocol: tcp + source: "{{ ansible_default_ipv4.address | ansible.utils.ipaddr('network') }}/24" + destination_port: "22" become: true - - name: add repo URL to sources.list - ansible.builtin.apt_repository: - # repo: "deb https://sdvdebianrepo.slub-dresden.de/deb-repository bullseye main" - repo: "deb http://bdv141.slub-dresden.de/deb-repository lza-testing main" - state: present + + handlers: + - name: update package cache + ansible.builtin.package: update_cache: true - mode: "0644" become: true diff --git a/molecule/virtualbox_debian11/molecule.yml b/molecule/virtualbox_debian11/molecule.yml index b465ee7fdb04176e73a27b1d56578bc84cc858e9..111fa2eaca777f235c0691a7e9171df63018bbe1 100644 --- a/molecule/virtualbox_debian11/molecule.yml +++ b/molecule/virtualbox_debian11/molecule.yml @@ -13,7 +13,7 @@ platforms: # https://github.com/ansible-community/molecule-vagrant#documentation # for more platform parameters. - name: molecule-test - box: debian/bullseye64 + box: debian/bookworm64 memory: 1024 # List of raw Vagrant `config` options. # provider_raw_config_args: @@ -21,7 +21,7 @@ platforms: # Dictionary of `config` options. config_options: ssh.keep_alive: true - ssh.remote_user: "'lza'" + ssh.remote_user: "lza" provisioner: name: ansible log: true @@ -29,7 +29,7 @@ provisioner: defaults: # https://stackoverflow.com/questions/57435811/ansible-molecule-pass-multiple-vault-ids # vault_identity_list: "@$HOME/.ansible/roles/lza_install_common.pass, @$HOME/.ansible/roles/passfile_1.pass" - vault_identity_list: "../lza_iesample.pass" + vault_identity_list: "../../../lza_iesample.pass" vvv: false playbooks: # create: ../resources/playbooks/create.yml diff --git a/tasks/install_packages.yml b/tasks/install_packages.yml index a6bc5beb7855e6e320a944a2bb7742c2b1b0adbf..76a4e61a84b6919f470880c8e416083cedaddb72 100644 --- a/tasks/install_packages.yml +++ b/tasks/install_packages.yml @@ -22,9 +22,12 @@ state: latest update_cache: true -- name: uninstall outdated perl-modules-5.28 package from Debian 11 Bullseye VMs +- name: uninstall outdated perl-modules packages from Debian 11/12 VMs ansible.builtin.apt: - name: 'perl-modules-5.28' + name: [ + 'perl-modules-5.28', + 'perl-modules-5.32', + ] state: absent - name: Install/Update Perl-Pakete @@ -38,6 +41,6 @@ 'libtext-csv-xs-perl', 'perl', 'perl-base', - 'perl-modules-5.32', + 'perl-modules-5.36', ] state: latest