--- # Everything the molecule job needs is installed here, at provision time, so a CI # run only executes tests: pinned tooling in a venv and the collections the roles use. # The role builds no test image: the scenarios are expected to pull theirs from a registry. # gitea_runner_collections_requirements_file is asserted non-empty in validate.yml. - name: Install molecule venv prerequisites become: true ansible.builtin.apt: name: - python3-venv - python3-pip - git # community.docker.docker_image runs on this host via the Docker SDK. - python3-requests - python3-docker state: present cache_valid_time: 3600 tags: [gitea_runner, molecule] - name: Install pinned molecule tooling into its venv become: true ansible.builtin.pip: name: - "molecule=={{ gitea_runner_molecule_version }}" - "molecule-plugins[docker]=={{ gitea_runner_molecule_plugins_version }}" - "ansible-core=={{ gitea_runner_molecule_ansible_core_version }}" - "docker=={{ gitea_runner_molecule_docker_sdk_version }}" virtualenv: "{{ gitea_runner_molecule_venv }}" virtualenv_command: python3 -m venv tags: [gitea_runner, molecule] # The collections come from gitea_runner_collections_requirements_file and are # reinstalled when it changes. requirements.sha256 in the collections path records the # checksum of the file the installed set came from; it is written only after a # successful install, so a failed install is retried on the next run (a guard on the # copied file changing would skip it forever). --force: without it ansible-galaxy skips # a collection it finds on any other collections path of this host and installs # nothing into -p, leaving the molecule job without the modules it needs. - name: Copy the pinned collections file to the runner host become: true ansible.builtin.copy: src: "{{ gitea_runner_collections_requirements_file }}" dest: "{{ gitea_runner_home }}/molecule-requirements.yml" owner: root group: root mode: "0644" tags: [gitea_runner, molecule] - name: Read the requirements checksum of the installed collections become: true ansible.builtin.slurp: src: "{{ gitea_runner_molecule_collections_path }}/requirements.sha256" register: gitea_runner_molecule_collections_stamp failed_when: false tags: [gitea_runner, molecule] - name: Install the collections the tested roles use when: gitea_runner_molecule_collections_stamp.content | default('') | b64decode | trim != gitea_runner_molecule_requirements_sha256 vars: gitea_runner_molecule_requirements_sha256: "{{ lookup('ansible.builtin.file', gitea_runner_collections_requirements_file) | hash('sha256') }}" tags: [gitea_runner, molecule] block: - name: Install the collections of the requirements file become: true ansible.builtin.command: argv: - "{{ gitea_runner_molecule_venv }}/bin/ansible-galaxy" - collection - install - --force - -r - "{{ gitea_runner_home }}/molecule-requirements.yml" - -p - "{{ gitea_runner_molecule_collections_path }}" changed_when: true tags: [gitea_runner, molecule] - name: Record the checksum of the installed collections become: true ansible.builtin.copy: content: "{{ gitea_runner_molecule_requirements_sha256 }}\n" dest: "{{ gitea_runner_molecule_collections_path }}/requirements.sha256" owner: root group: root mode: "0644" tags: [gitea_runner, molecule]