--- - name: Set random value ansible.builtin.set_fact: nodepool_diskimage_name: "dummy-{{ lookup('community.general.random_string', min_numeric=8, length=8) }}-image" # First attempt a negative test where we expect a failure - name: Ensure nodepool directory exists ansible.builtin.file: path: "{{ item }}" state: directory loop: - "{{ config_path }}/nodepool" - "{{ config_path }}/nodepool/dib-ansible" - name: Set bad Nodepool builder config ansible.builtin.blockinfile: content: | DiskDisk: {} path: "{{ config_path }}/nodepool/nodepool-builder.yaml" create: true - name: Commit file in the config repo ansible.builtin.command: "{{ item }}" args: chdir: "{{ config_path }}" loop: - "git add nodepool/nodepool-builder.yaml" - "git commit -m 'Add nodepool/nodepool-builder.yaml'" - ansible.builtin.include_role: name: "health-check/repo-submit-change" vars: ensure_job_failure: true # Now proceed with adding a correct tenant file - name: Reset the config repo ansible.builtin.command: "git reset --hard gerrit/master" args: chdir: "{{ config_path }}" # As nodepool builder will connected to the image-builder node (which is the microshift node in CI usecase) # here we ensure that the nodepool-builder pod can connect - name: Get nodepool-builder public SSH key ansible.builtin.shell: | go run main.go {{ cli_global_flags }} nodepool get builder-ssh-key 2> /dev/null args: chdir: "{{ zuul.project.src_dir }}" register: nodepool_get_key - name: Ensure nodepool user available on the controller delegate_to: "{{ os_host }}" become: true ansible.builtin.user: name: nodepool comment: nodepool account is used by nodepool-builder to host account to build cloud images - name: Set nodepool user authorized_keys delegate_to: "{{ os_host }}" become: true ansible.posix.authorized_key: user: nodepool state: present key: "{{ nodepool_get_key.stdout }}" - name: Ensure nodepool-builder pod can connect via SSH using the 'nodepool' user to the image-builder machine ansible.builtin.command: > kubectl exec -it nodepool-builder-0 -c nodepool-builder -- ssh -o StrictHostKeyChecking=no nodepool@{{ microshift_host }} hostname - name: Ensure nodepool directory exists ansible.builtin.file: path: "{{ item }}" state: directory loop: - "{{ config_path }}/nodepool" - "{{ config_path }}/nodepool/dib-ansible" - name: Define nodepool-builder.yaml default content ansible.builtin.copy: content: | diskimages: - dib-cmd: /usr/local/bin/dib-ansible dummy.yaml formats: - raw name: {{ nodepool_diskimage_name }} pause: false username: zuul-worker dest: "{{ config_path }}/nodepool/nodepool-builder.yaml" - name: Define the inventory file ansible.builtin.copy: content: | --- ungrouped: hosts: image-builder: ansible_host: {{ microshift_host }} ansible_user: nodepool dest: "{{ config_path }}/nodepool/dib-ansible/inventory.yaml" - name: Define dummy cloud image playbook dummy.yaml ansible.builtin.copy: content: | --- - name: Dummy cloud image build playbook hosts: image-builder tasks: - ansible.builtin.debug: msg: "Hello from build of {{ nodepool_diskimage_name }}" - name: Copy Zuul public key on the image-builder copy: src: /var/lib/zuul-ssh-key/pub dest: /tmp/zuul-ssh-key.pub - name: Simulate an image built on the image-builder host file: path: /tmp/dummy-cloud-image.raw state: touch - name: Fetch the image on nodepool ansible.posix.synchronize: mode: pull src: /tmp/dummy-cloud-image.raw dest: "{{ '{{' }} image_output {{ '}}' }}.raw" dest: "{{ config_path }}/nodepool/dib-ansible/dummy.yaml" - name: Commit file in the config repo ansible.builtin.command: "{{ item }}" args: chdir: "{{ config_path }}" loop: - "git add nodepool/nodepool-builder.yaml" - "git add nodepool/dib-ansible/dummy.yaml" - "git add nodepool/dib-ansible/inventory.yaml" - "git commit -m 'Add nodepool builder image config'" - name: Update config repo change ansible.builtin.include_role: name: "health-check/repo-submit-change" - name: "Check that {{ nodepool_diskimage_name }} label exists in the destination file" ansible.builtin.shell: | kubectl exec nodepool-builder-0 -- grep "name: {{ nodepool_diskimage_name }}" /etc/nodepool/nodepool.yaml - name: "Check that witness message is available in build logs" ansible.builtin.shell: | kubectl exec nodepool-builder-0 -- bash -c "grep 'Hello from build of {{ nodepool_diskimage_name }}' /var/lib/nodepool/builds/logs/*" register: witness until: witness is success delay: 5 retries: 6 - name: "Check that nodepool dib-image-list reports the new image" ansible.builtin.shell: | kubectl exec nodepool-builder-0 -- bash -c "nodepool dib-image-list | grep {{ nodepool_diskimage_name }} | grep ready" register: dib_image_list until: dib_image_list is success delay: 5 retries: 6 # Ansible plugin errors will appear in playbook outputs in the following format: # [WARNING]: Failure using method (XXXX) in callback plugin () so we can look for # the specific "in callback plugin" string in the logs. - name: "Ensure the timestamp callback plugin works as intended" ansible.builtin.shell: | kubectl exec nodepool-builder-0 -- bash -c "grep 'in callback plugin' /var/lib/nodepool/builds/logs/*" register: timestamp_error failed_when: timestamp_error is success ignore_errors: true