Add: proxy_env in defaults variables and use it in needed tasks

This commit is contained in:
Ali Mehraji 2024-12-08 19:20:24 +03:30
parent 2050a073e5
commit fb2a9c1f36
5 changed files with 24 additions and 0 deletions

View File

@ -1,4 +1,11 @@
---
# ---------------------------------------------------------------------
# Proxy variables (optional) for download packages using a proxy server
proxy_env:
http_proxy: http://192.168.20.112:10808
https_proxy: http://192.168.20.112:10808
# ---------------------------------------------------------------------
# Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition).
docker_edition: 'ce'
docker_packages:

View File

@ -25,6 +25,7 @@
url: "{{ docker_compose_url }}"
dest: "{{ docker_compose_path }}"
mode: 0755
environment: "{{ proxy_env | default({}) }}"
when: >
(docker_compose_current_version is not defined)
or (docker_compose_current_version | length == 0)

View File

@ -20,6 +20,7 @@
package:
name: "{{ docker_packages }}"
state: "{{ docker_packages_state }}"
environment: "{{ proxy_env | default({}) }}"
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "ansible_version.full is version_compare('2.12', '<') or ansible_os_family not in ['RedHat', 'Debian']"
@ -29,6 +30,7 @@
name: "{{ docker_packages }}"
state: "{{ docker_packages_state }}"
allow_downgrade: true
environment: "{{ proxy_env | default({}) }}"
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "ansible_version.full is version_compare('2.12', '>=') and ansible_os_family in ['RedHat', 'Debian']"
@ -37,6 +39,7 @@
package:
name: "{{ docker_compose_package }}"
state: "{{ docker_compose_package_state }}"
environment: "{{ proxy_env | default({}) }}"
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "docker_install_compose_plugin | bool == true and (ansible_version.full is version_compare('2.12', '<') or ansible_os_family not in ['RedHat', 'Debian'])"
@ -46,6 +49,7 @@
name: "{{ docker_compose_package }}"
state: "{{ docker_compose_package_state }}"
allow_downgrade: true
environment: "{{ proxy_env | default({}) }}"
notify: restart docker
ignore_errors: "{{ ansible_check_mode }}"
when: "docker_install_compose_plugin | bool == true and ansible_version.full is version_compare('2.12', '>=') and ansible_os_family in ['RedHat', 'Debian']"

View File

@ -15,6 +15,7 @@
state: absent
filename: "{{ docker_apt_filename }}"
update_cache: true
environment: "{{ proxy_env | default({}) }}"
when: docker_add_repo | bool
- # See https://docs.docker.com/engine/install/debian/#uninstall-old-versions
@ -29,6 +30,7 @@
- apt-transport-https
- ca-certificates
state: present
environment: "{{ proxy_env | default({}) }}"
when: docker_add_repo | bool
- name: Ensure directory exists for /etc/apt/keyrings
@ -46,15 +48,18 @@
checksum: "{{ docker_apt_gpg_key_checksum | default(omit) }}"
register: add_repository_key
ignore_errors: "{{ docker_apt_ignore_key_error }}"
environment: "{{ proxy_env | default({}) }}"
when: docker_add_repo | bool
- name: Ensure curl is present (on older systems without SNI).
package: name=curl state=present
environment: "{{ proxy_env | default({}) }}"
when: add_repository_key is failed and docker_add_repo | bool
- name: Add Docker apt key (alternative for older systems without SNI).
shell: >
curl -sSL {{ docker_apt_gpg_key }} | apt-key add -
environment: "{{ proxy_env | default({}) }}"
when: add_repository_key is failed and docker_add_repo | bool
- name: Add Docker repository.
@ -63,4 +68,5 @@
state: present
filename: "{{ docker_apt_filename }}"
update_cache: true
environment: "{{ proxy_env | default({}) }}"
when: docker_add_repo | bool

View File

@ -11,6 +11,7 @@
rpm_key:
key: "{{ docker_yum_gpg_key }}"
state: present
environment: "{{ proxy_env | default({}) }}"
when: docker_add_repo | bool
- name: Add Docker repository.
@ -20,6 +21,7 @@
owner: root
group: root
mode: 0644
environment: "{{ proxy_env | default({}) }}"
when: docker_add_repo | bool
- name: Configure Docker Nightly repo.
@ -30,6 +32,7 @@
value: '{{ docker_yum_repo_enable_nightly }}'
mode: 0644
no_extra_spaces: true
environment: "{{ proxy_env | default({}) }}"
when: docker_add_repo | bool
- name: Configure Docker Test repo.
@ -40,6 +43,7 @@
value: '{{ docker_yum_repo_enable_test }}'
mode: 0644
no_extra_spaces: true
environment: "{{ proxy_env | default({}) }}"
when: docker_add_repo | bool
- name: Configure containerd on RHEL 8.
@ -53,9 +57,11 @@
package:
name: container-selinux
state: present
environment: "{{ proxy_env | default({}) }}"
- name: Ensure containerd.io is installed.
package:
name: containerd.io
state: present
environment: "{{ proxy_env | default({}) }}"
when: ansible_distribution_major_version | int == 8