๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible-playbooks/roles/common/tasks/alpine.yml

95 lines
2.3 KiB

2 years ago
- name: setup timezone
shell:
cmd: PATH=$PATH:/sbin; /sbin/setup-timezone -z {{ timezone | quote }}
chdir: /sbin
creates: "{{ ('/etc/zoneinfo', timezone) | path_join }}"
notify: restart syslog
when: timezone is string
- name: flush handlers
meta: flush_handlers
- name: upgrade alpine version
replace:
path: /etc/apk/repositories
regexp: '/alpine/v\d+\.\d+/'
replace: '/alpine/v{{ alpine_version }}/'
- name: change apk repository
replace:
path: /etc/apk/repositories
regexp: '^https:\/\/dl-cdn\.alpinelinux\.org\/alpine\/'
replace: 'https://mirror.yandex.ru/mirrors/alpine/'
when: use_alternative_apk_repo | d(false) == true
- block:
- name: update repository index
community.general.apk:
update_cache: yes
changed_when: no
register: apk_result
rescue:
- name: fix repository keys
command:
cmd: /sbin/apk fix --allow-untrusted alpine-keys
when: "'UNTRUSTED signature' in apk_result.stderr"
- name: update repository index in untrusted mode
command:
cmd: /sbin/apk --allow-untrusted update
when: "'UNTRUSTED signature' in apk_result.stderr"
- name: upgrade basic dependencies in untrusted mode
command:
cmd: /sbin/apk --allow-untrusted upgrade apk-tools alpine-keys
when: "'UNTRUSTED signature' in apk_result.stderr"
- name: update repository index
community.general.apk:
update_cache: yes
changed_when: no
- name: check if there are any updates
command:
cmd: /sbin/apk list -u
register: updates_found
changed_when: no
- name: pause and confirm updates
pause:
prompt: "{{ updates_found.stdout }}"
when: (updates_found.stdout | length > 0) and (interactive | d(true) == true) and (hosts_strategy | d('') != 'free')
changed_when: updates_found.stdout | length > 0
- name: upgrade all packages if updates are found
community.general.apk:
upgrade: yes
when: updates_found.stdout | length > 0
- name: collect apk-new files
find:
paths:
- /etc
- /usr
- /var
patterns: "*.apk-new"
recurse: yes
depth: 8
register: new_files
- name: remove apk-new files
file:
path: "{{ item.path }}"
state: absent
loop: "{{ new_files.files | flatten(levels=1) }}"