|
| 1 | +--- |
| 2 | + |
| 3 | +- name: Run prechecks |
| 4 | + include_tasks: prechecks.yml |
| 5 | + |
| 6 | +- name: Create temporary file for pkrvars.hcl |
| 7 | + ansible.builtin.tempfile: |
| 8 | + state: file |
| 9 | + suffix: .pkrvars.hcl |
| 10 | + register: pkrvars_hcl_file |
| 11 | + |
| 12 | +- name: Make Packer vars file |
| 13 | + template: |
| 14 | + src: builder.pkrvars.hcl.j2 |
| 15 | + dest: "{{ pkrvars_hcl_file.path }}" |
| 16 | + |
| 17 | +- name: Create temporary image-build inventory directory |
| 18 | + ansible.builtin.tempfile: |
| 19 | + state: directory |
| 20 | + prefix: image-build. |
| 21 | + register: image_build_inventory |
| 22 | + |
| 23 | +- name: Symlink "everything" layout to image-build inventory |
| 24 | + file: |
| 25 | + state: link |
| 26 | + src: "{{ playbook_dir }}/vendor/stackhpc/ansible-slurm-appliance/environments/common/layouts/everything" |
| 27 | + dest: "{{ image_build_inventory.path }}/groups" |
| 28 | + |
| 29 | +- name: Symlink CAAS group_vars to image-build inventory |
| 30 | + file: |
| 31 | + state: link |
| 32 | + src: "{{ playbook_dir }}/group_vars" |
| 33 | + dest: "{{ image_build_inventory.path }}/group_vars" |
| 34 | + |
| 35 | +- name: Add builder vars to image-build inventory hosts file |
| 36 | + copy: |
| 37 | + dest: "{{ image_build_inventory.path }}/hosts" |
| 38 | + content: | |
| 39 | + [builder:vars] |
| 40 | + {% if image_build_ssh_bastion_host is defined %} |
| 41 | + ansible_ssh_common_args={{ image_build_ansible_ssh_common_args }} |
| 42 | + {% endif %} |
| 43 | + {% for k,v in image_build_builder_group_vars.items() -%} |
| 44 | + {{ k }}={{ v }} |
| 45 | + {% endfor -%} |
| 46 | +
|
| 47 | +- name: Create temporary file for ansible.cfg |
| 48 | + ansible.builtin.tempfile: |
| 49 | + state: file |
| 50 | + suffix: ansible.cfg |
| 51 | + register: ansible_cfg_file |
| 52 | + |
| 53 | +- name: Template image-build ansible.cfg |
| 54 | + template: |
| 55 | + src: ansible.cfg.j2 |
| 56 | + dest: "{{ ansible_cfg_file.path }}" |
| 57 | + |
| 58 | +- name: Packer init |
| 59 | + command: |
| 60 | + cmd: | |
| 61 | + packer init . |
| 62 | + chdir: "{{ image_build_packer_root_path }}" |
| 63 | + |
| 64 | +- name: Build image with packer |
| 65 | + command: |
| 66 | + cmd: | |
| 67 | + packer build -only openstack.openhpc -var-file={{ pkrvars_hcl_file.path }} openstack.pkr.hcl |
| 68 | + chdir: "{{ image_build_packer_root_path }}" |
| 69 | + environment: |
| 70 | + ANSIBLE_CONFIG: "{{ ansible_cfg_file.path }}" |
| 71 | + PACKER_LOG: "1" |
| 72 | + PACKER_LOG_PATH: "{{ lookup('ansible.builtin.env', 'PACKER_LOG_PATH', default='/tmp/packer-build.log') }}" |
| 73 | + |
| 74 | +- name: Parse packer-manifest.json |
| 75 | + set_fact: |
| 76 | + packer_manifest: "{{ lookup('file', '/tmp/builder.manifest.json') | from_json }}" |
| 77 | + |
| 78 | +- name: Extract image-build data |
| 79 | + set_fact: |
| 80 | + image_build_data: "{{ packer_manifest.builds | selectattr('packer_run_uuid', 'eq', packer_manifest.last_run_uuid) | first }}" |
0 commit comments