Update to 2022-02-09 17:00

This commit is contained in:
Daniel Berteaud
2022-02-09 17:00:06 +01:00
parent 00b3d728c8
commit 6f6d3b7382
9 changed files with 75 additions and 74 deletions

View File

@@ -1,10 +1,21 @@
---
# System proxy to use. If undefined or set to an empty string
# proxy will be disabled
# system_proxy: http://proxyout.example.org:3128
# List of hosts for which no proxy should be used
system_proxy_base_no_proxy:
- 127.0.0.1
- localhost
- "{{ inventory_hostname | regex_replace('^([^.]+)\\..*','\\1') }}"
- "{{ inventory_hostname }}"
# Can be used to add no_proxy hosts without overriding the default ones
system_proxy_extra_no_proxy: []
system_proxy_no_proxy: "{{ system_proxy_base_no_proxy + system_proxy_extra_no_proxy }}"
# List of protocols for which env variables will be set (if a proxy is configured)
system_proxy_proto:
- http
- https
- ftp

View File

@@ -0,0 +1,17 @@
---
- name: Config proxy for apt
copy:
content: |
Acquire::http::Proxy "{{ system_proxy }}";
Acquire::https::Proxy "{{ system_proxy }}";
dest: /etc/apt/apt.conf.d/10proxy
when:
- system_proxy is defined
- system_proxy != ''
tags: proxy
- name: Remove proxy from apt config
file: path=/etc/apt/apt.conf.d/10proxy state=absent
when: system_proxy is not defined or system_proxy == ''
tags: proxy

View File

@@ -0,0 +1,20 @@
---
- name: Configure proxy for yum
ini_file:
path: /etc/yum.conf
section: main
option: proxy
value: "{{ (system_proxy is defined and system_proxy != '') | ternary(system_proxy,'') }}"
state: "{{ (system_proxy is defined and system_proxy != '') | ternary('present','absent') }}"
tags: proxy
- name: Configure proxy for dnf
ini_file:
path: /etc/dnf/yum.conf
section: main
option: proxy
value: "{{ (system_proxy is defined and system_proxy != '') | ternary(system_proxy,'') }}"
state: "{{ (system_proxy is defined and system_proxy != '') | ternary('present','absent') }}"
when: ansible_distribution_major_version is version('8', '>=')
tags: proxy

View File

@@ -10,13 +10,7 @@
regexp: "^{{ item }}=.*"
line: "{{ item }}={{ (system_proxy is defined and system_proxy != '') | ternary(system_proxy,'') }}"
state: "{{ (system_proxy is defined and system_proxy != '') | ternary('present','absent') }}"
with_items:
- http_proxy
- HTTP_PROXY
- https_proxy
- HTTPS_PROXY
- ftp_proxy
- FTP_PROXY
with_items: "{{ system_proxy_proto | map('regex_replace', '^(.*)$', '\\1_proxy') | list }} + {{ system_proxy_proto | map('regex_replace', '^(.*)$', '\\1_proxy') | map('upper') | list }}"
tags: proxy
- name: Set proxy exceptions
@@ -30,55 +24,15 @@
- NO_PROXY
tags: proxy
- name: Creates systemd.conf.d dir
file: path=/etc/systemd/system.conf.d state=directory
when: ansible_service_mgr == 'systemd'
- when: ansible_service_mgr == 'systemd'
block:
- name: Creates systemd.conf.d dir
file: path=/etc/systemd/system.conf.d state=directory
- name: Deploy a systemd snippet for default proxy
template: src=systemd.conf.j2 dest=/etc/systemd/system.conf.d/proxy.conf
notify: reload systemd
tags: proxy
- name: Deploy a systemd snippet for default proxy
template: src=systemd.conf.j2 dest=/etc/systemd/system.conf.d/proxy.conf
notify: reload systemd
when: ansible_service_mgr == 'systemd'
tags: proxy
- name: Configure proxy for yum
ini_file:
path: /etc/yum.conf
section: main
option: proxy
value: "{{ (system_proxy is defined and system_proxy != '') | ternary(system_proxy,'') }}"
state: "{{ (system_proxy is defined and system_proxy != '') | ternary('present','absent') }}"
when: ansible_os_family == 'RedHat'
tags: proxy
- name: Configure proxy for dnf
ini_file:
path: /etc/dnf/yum.conf
section: main
option: proxy
value: "{{ (system_proxy is defined and system_proxy != '') | ternary(system_proxy,'') }}"
state: "{{ (system_proxy is defined and system_proxy != '') | ternary('present','absent') }}"
when:
- ansible_os_family == 'RedHat'
- ansible_distribution_major_version is version('8', '>=')
tags: proxy
- name: Config proxy for apt
copy:
content: |
Acquire::http::Proxy "{{ system_proxy }}";
Acquire::https::Proxy "{{ system_proxy }}";
dest: /etc/apt/apt.conf.d/10proxy
when:
- ansible_os_family == 'Debian'
- system_proxy is defined
- system_proxy != ''
tags: proxy
- name: Remove proxy from apt config
file: path=/etc/apt/apt.conf.d/10proxy state=absent
when:
- ansible_os_family == 'Debian'
- system_proxy is not defined or system_proxy == ''
tags: proxy
- include: "{{ ansible_os_family }}.yml"

View File

@@ -1,12 +1,10 @@
#!/bin/bash
{% if system_proxy is defined and system_proxy != '' %}
export http_proxy={{ system_proxy }}
export https_proxy={{ system_proxy }}
export ftp_proxy={{ system_proxy }}
export HTTP_PROXY={{ system_proxy }}
export HTTPS_PROXY={{ system_proxy }}
export FTP_PROXY={{ system_proxy }}
{% for proto in system_proxy_proto %}
export {{ proto }}_proxy={{ system_proxy }}
export {{ proto | upper }}_PROXY={{ system_proxy }}
{% endfor %}
export no_proxy='{{ system_proxy_no_proxy | join(',') }}'
export NO_PROXY='{{ system_proxy_no_proxy | join(',') }}'
{% endif %}

View File

@@ -1,6 +1,6 @@
[Manager]
{% if system_proxy is defined and system_proxy != '' %}
DefaultEnvironment=http_proxy={{ system_proxy }} https_proxy={{ system_proxy }} ftp_proxy={{ system_proxy }} HTTP_PROXY={{ system_proxy }} HTTPS_PROXY={{ system_proxy }} FTP_PROXY={{ system_proxy }} no_proxy={{ system_proxy_no_proxy | join(',') }} NO_PROXY={{ system_proxy_no_proxy | join(',') }}
DefaultEnvironment={% for proto in system_proxy_proto %}{{ proto }}_proxy={{ system_proxy }} {{ proto | upper }}_PROXY={{ system_proxy }} {% endfor %}no_proxy={{ system_proxy_no_proxy | join(',') }} NO_PROXY={{ system_proxy_no_proxy | join(',') }}
{% else %}
# No proxy configured
{% endif %}