Skip to content

Commit

Permalink
Permit to provide proxies for installation
Browse files Browse the repository at this point in the history
  • Loading branch information
t.fouchard authored and angstwad committed Dec 18, 2018
1 parent 55f7dca commit 6edfac4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 12 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ daemon_json:
# Be aware that granted users can easily get full root access on the docker host system!
docker_group_members: []

# Shall we have to set the docker proxies the same as those used during installation
docker_use_install_proxies: true

# configurable proxies: a reasonable default is to re-use the proxy from ansible_env:
# docker_http_proxy: "{{ ansible_env.http_proxy|default('') }}"
# Notes:
# if docker_http_proxy=="" the role sets HTTP_PROXY="" (useful to 'empty' existing ENV var)
# if docker_http_proxy is undefined the role will not set/modify any ENV vars
docker_http_proxy:
docker_https_proxy:
docker_no_proxy:
docker_http_proxy: "{{proxy_env.http_proxy if (docker_use_install_proxies and proxy_env is defined and proxy_env.http_proxy is defined) else \"\"}}"
docker_https_proxy: "{{proxy_env.https_proxy if (docker_use_install_proxies and proxy_env is defined and proxy_env.https_proxy is defined) else \"\"}}"
docker_no_proxy: "{{proxy_env.no_proxy if (docker_use_install_proxies and proxy_env is defined and proxy_env.no_proxy is defined) else \"\"}}"

# Flags for whether to install pip packages
pip_install_pip: true
Expand Down Expand Up @@ -105,3 +108,9 @@ ufw_set_forward_policy: true
# Set to 'no' if docker daemon shall not be started.
# (e.g. in case of a machine which only controls other docker hosts via docker-machine)
start_docker_daemon: true

# Specify here the proxies config to use for installation
#proxy_env:
# http_proxy: 'http://192.168.0.10'
# https_proxy: 'http://192.168.0.10'
# no_proxy: '192.168.0.20'
10 changes: 10 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
state: present
update_cache: yes
cache_valid_time: "{{ docker_apt_cache_valid_time }}"
environment: "{{proxy_env if proxy_env is defined else {}}}"
when: docker_aufs_enabled and ansible_distribution_version is version_compare('14.04', '==') and ansible_kernel is version_compare('4.4', '<')

register: linux_image_extra_install
Expand All @@ -50,6 +51,7 @@
state: present
update_cache: yes
cache_valid_time: "{{ docker_apt_cache_valid_time }}"
environment: "{{proxy_env if proxy_env is defined else {}}}"
when: linux_image_extra_install is failed

- name: Ensure dirmngr is available
Expand All @@ -58,37 +60,43 @@
state: present
update_cache: yes
cache_valid_time: "{{ docker_apt_cache_valid_time }}"
environment: "{{proxy_env if proxy_env is defined else {}}}"

- name: Add Docker repository key
apt_key:
id: "{{ apt_key_sig }}"
keyserver: "{{ apt_key_url }}"
state: present
register: add_repository_key
environment: "{{proxy_env if proxy_env is defined else {}}}"
ignore_errors: true

- name: Alternative | Add Docker repository key
shell: "apt-key adv --fetch-keys {{ apt_key_url }}"
environment: "{{proxy_env if proxy_env is defined else {}}}"
when: add_repository_key is failed

- name: HTTPS APT transport for Docker repository
apt:
name: apt-transport-https
state: present
environment: "{{proxy_env if proxy_env is defined else {}}}"

- name: Add Docker repository and update apt cache
apt_repository:
repo: "{{ apt_repository }}"
mode: '644'
update_cache: yes
state: present
environment: "{{proxy_env if proxy_env is defined else {}}}"

- name: Install (or update) docker package
apt:
name: "{{ docker_pkg_name }}"
state: "{{ 'latest' if update_docker_package else 'present' }}"
update_cache: "{{ update_docker_package }}"
cache_valid_time: "{{ docker_apt_cache_valid_time }}"
environment: "{{proxy_env if proxy_env is defined else {}}}"

- name: Set systemd playbook var
set_fact:
Expand Down Expand Up @@ -186,6 +194,7 @@
state: latest
update_cache: yes
cache_valid_time: "{{ docker_apt_cache_valid_time }}"
environment: "{{proxy_env if proxy_env is defined else {}}}"

# Display an informative message if the docker-compose version needs to be downgraded
- name: Docker-compose version downgrade
Expand Down Expand Up @@ -232,6 +241,7 @@
- name: docker-compose
version: "{{ _pip_version_docker_compose }}"
install: "{{ pip_install_docker_compose }}"
environment: "{{proxy_env if proxy_env is defined else {}}}"
when: item.install|bool

- name: Check if /etc/updatedb.conf exists
Expand Down

0 comments on commit 6edfac4

Please sign in to comment.