init
This commit is contained in:
48
ansible/roles/packer/install/tasks/main.yml
Normal file
48
ansible/roles/packer/install/tasks/main.yml
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
- name: install base deps for HashiCorp repo
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
name:
|
||||
- ca-certificates # чтобы качать по HTTPS
|
||||
- curl # чтобы скачать packer/плагины
|
||||
- gnupg
|
||||
- lsb-release
|
||||
- unzip # packer часто в zip
|
||||
state: present
|
||||
|
||||
- name: ensure keyrings dir exists
|
||||
ansible.builtin.file:
|
||||
path: /usr/share/keyrings
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: add HashiCorp GPG key (dearmored)
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
curl -fsSL https://apt.releases.hashicorp.com/gpg \
|
||||
| gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
|
||||
args:
|
||||
executable: /bin/bash
|
||||
creates: /usr/share/keyrings/hashicorp-archive-keyring.gpg
|
||||
|
||||
- name: add HashiCorp APT repository
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/apt/sources.list.d/hashicorp.list
|
||||
mode: "0644"
|
||||
content: |
|
||||
deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com {{ ansible_distribution_release }} main
|
||||
|
||||
- name: install packer
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
name: packer
|
||||
state: present
|
||||
|
||||
- name: check packer version
|
||||
ansible.builtin.command: packer version
|
||||
register: packer_version
|
||||
changed_when: false
|
||||
|
||||
- name: print packer version
|
||||
ansible.builtin.debug:
|
||||
var: packer_version.stdout
|
||||
33
ansible/roles/packer/run/tasks/main.yml
Normal file
33
ansible/roles/packer/run/tasks/main.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
- name: ensure packer exists
|
||||
ansible.builtin.command: packer version
|
||||
changed_when: false
|
||||
|
||||
- name: packer init
|
||||
ansible.builtin.command: packer init .
|
||||
args:
|
||||
chdir: "{{ packer_config_dir }}"
|
||||
changed_when: false
|
||||
|
||||
- name: packer fmt
|
||||
ansible.builtin.command: packer fmt -recursive .
|
||||
args:
|
||||
chdir: "{{ packer_config_dir }}"
|
||||
changed_when: false
|
||||
|
||||
- name: packer validate
|
||||
ansible.builtin.command: packer validate .
|
||||
args:
|
||||
chdir: "{{ packer_config_dir }}"
|
||||
changed_when: false
|
||||
|
||||
- name: packer build
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
stdbuf -oL -eL packer build -on-error=cleanup -timestamp-ui .
|
||||
args:
|
||||
chdir: "{{ packer_config_dir }}"
|
||||
executable: /bin/bash
|
||||
environment:
|
||||
PACKER_LOG: "1"
|
||||
PACKER_LOG_PATH: ""
|
||||
Reference in New Issue
Block a user