mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 06:10:22 -07:00
Properly handle unauthenticated yum proxy config (#51915)
Fixes #51548 Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
parent
bcefd61437
commit
2721ed260e
3 changed files with 93 additions and 22 deletions
2
changelogs/fragments/yum-unauthenticated-proxy.yaml
Normal file
2
changelogs/fragments/yum-unauthenticated-proxy.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- yum - properly handle a proxy config in yum.conf for an unauthenticated proxy
|
|
@ -724,6 +724,12 @@ class YumModule(YumDnf):
|
||||||
r"(http://)",
|
r"(http://)",
|
||||||
r"\g<1>" + namepass, proxy_url
|
r"\g<1>" + namepass, proxy_url
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
for item in scheme:
|
||||||
|
os.environ[item + "_proxy"] = re.sub(
|
||||||
|
r"(http://)",
|
||||||
|
r"\g<1>", proxy_url
|
||||||
|
)
|
||||||
yield
|
yield
|
||||||
except yum.Errors.YumBaseError:
|
except yum.Errors.YumBaseError:
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
- name: test yum proxy settings
|
- name: test yum proxy settings
|
||||||
block:
|
block:
|
||||||
- yum:
|
- name: install tinyproxy
|
||||||
|
yum:
|
||||||
name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/tinyproxy-1.10.0-3.el7.x86_64.rpm'
|
name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/tinyproxy-1.10.0-3.el7.x86_64.rpm'
|
||||||
state: installed
|
state: installed
|
||||||
|
|
||||||
- lineinfile:
|
|
||||||
path: /etc/tinyproxy/tinyproxy.conf
|
|
||||||
line: "BasicAuth 1testuser 1testpassword"
|
|
||||||
state: present
|
|
||||||
|
|
||||||
# systemd doesn't play nice with this in a container for some reason
|
# systemd doesn't play nice with this in a container for some reason
|
||||||
- shell: tinyproxy
|
- name: start tinyproxy (systemd with tiny proxy does not work in container)
|
||||||
|
shell: tinyproxy
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- lineinfile:
|
# test proxy without auth
|
||||||
|
- name: set unauthenticated proxy in yum.conf
|
||||||
|
lineinfile:
|
||||||
path: /etc/yum.conf
|
path: /etc/yum.conf
|
||||||
line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888"
|
line: "proxy=http://127.0.0.1:8888"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- yum:
|
- name: install ninvaders with unauthenticated proxy
|
||||||
|
yum:
|
||||||
name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm'
|
name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm'
|
||||||
state: installed
|
state: installed
|
||||||
register: yum_proxy_result
|
register: yum_proxy_result
|
||||||
|
@ -29,31 +29,87 @@
|
||||||
- "'msg' in yum_proxy_result"
|
- "'msg' in yum_proxy_result"
|
||||||
- "'rc' in yum_proxy_result"
|
- "'rc' in yum_proxy_result"
|
||||||
|
|
||||||
- yum:
|
- name: uninstall ninvaders with unauthenticated proxy
|
||||||
|
yum:
|
||||||
|
name: ninvaders
|
||||||
|
state: absent
|
||||||
|
register: yum_proxy_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "yum_proxy_result.changed"
|
||||||
|
- "'msg' in yum_proxy_result"
|
||||||
|
- "'rc' in yum_proxy_result"
|
||||||
|
|
||||||
|
- name: unset unauthenticated proxy in yum.conf
|
||||||
|
lineinfile:
|
||||||
|
path: /etc/yum.conf
|
||||||
|
line: "proxy=http://127.0.0.1:8888"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
# test proxy with auth
|
||||||
|
- name: set authenticated proxy config in tinyproxy.conf
|
||||||
|
lineinfile:
|
||||||
|
path: /etc/tinyproxy/tinyproxy.conf
|
||||||
|
line: "BasicAuth 1testuser 1testpassword"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
# systemd doesn't play nice with this in a container for some reason
|
||||||
|
- name: SIGHUP tinyproxy to reload config (workaround because of systemd+tinyproxy in container)
|
||||||
|
shell: kill -HUP $(ps -ef | grep tinyproxy | grep -v grep | awk '{print $2}')
|
||||||
|
changed_when: false
|
||||||
|
args:
|
||||||
|
executable: /usr/bin/bash
|
||||||
|
|
||||||
|
- name: set authenticated proxy config in yum.conf
|
||||||
|
lineinfile:
|
||||||
|
path: /etc/yum.conf
|
||||||
|
line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: install ninvaders with authenticated proxy
|
||||||
|
yum:
|
||||||
|
name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm'
|
||||||
|
state: installed
|
||||||
|
register: yum_proxy_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- "yum_proxy_result.changed"
|
||||||
|
- "'msg' in yum_proxy_result"
|
||||||
|
- "'rc' in yum_proxy_result"
|
||||||
|
|
||||||
|
- name: uninstall ninvaders with authenticated proxy
|
||||||
|
yum:
|
||||||
name: ninvaders
|
name: ninvaders
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- lineinfile:
|
- name: unset authenticated proxy config in yum.conf
|
||||||
|
lineinfile:
|
||||||
path: /etc/yum.conf
|
path: /etc/yum.conf
|
||||||
line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888"
|
line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- lineinfile:
|
- name: set proxy config in yum.conf
|
||||||
|
lineinfile:
|
||||||
path: /etc/yum.conf
|
path: /etc/yum.conf
|
||||||
line: "proxy=http://127.0.0.1:8888"
|
line: "proxy=http://127.0.0.1:8888"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- lineinfile:
|
- name: set proxy_username config in yum.conf
|
||||||
|
lineinfile:
|
||||||
path: /etc/yum.conf
|
path: /etc/yum.conf
|
||||||
line: "proxy_username=1testuser"
|
line: "proxy_username=1testuser"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- lineinfile:
|
- name: set proxy_password config in yum.conf
|
||||||
|
lineinfile:
|
||||||
path: /etc/yum.conf
|
path: /etc/yum.conf
|
||||||
line: "proxy_password=1testpassword"
|
line: "proxy_password=1testpassword"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- yum:
|
- name: install ninvaders with proxy, proxy_username, and proxy_password config in yum.conf
|
||||||
|
yum:
|
||||||
name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm'
|
name: 'https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/yum/ninvaders-0.1.1-18.el7.x86_64.rpm'
|
||||||
state: installed
|
state: installed
|
||||||
register: yum_proxy_result
|
register: yum_proxy_result
|
||||||
|
@ -65,30 +121,37 @@
|
||||||
- "'rc' in yum_proxy_result"
|
- "'rc' in yum_proxy_result"
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- yum:
|
#cleanup
|
||||||
|
- name: uninstall tinyproxy
|
||||||
|
yum:
|
||||||
name: tinyproxy
|
name: tinyproxy
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- yum:
|
- name: uninstall ninvaders
|
||||||
|
yum:
|
||||||
name: ninvaders
|
name: ninvaders
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- lineinfile:
|
- name: ensure unset authenticated proxy
|
||||||
|
lineinfile:
|
||||||
path: /etc/yum.conf
|
path: /etc/yum.conf
|
||||||
line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888"
|
line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- lineinfile:
|
- name: ensure unset proxy
|
||||||
|
lineinfile:
|
||||||
path: /etc/yum.conf
|
path: /etc/yum.conf
|
||||||
line: "proxy=http://127.0.0.1:8888"
|
line: "proxy=http://127.0.0.1:8888"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- lineinfile:
|
- name: ensure unset proxy_username
|
||||||
|
lineinfile:
|
||||||
path: /etc/yum.conf
|
path: /etc/yum.conf
|
||||||
line: "proxy_username=1testuser"
|
line: "proxy_username=1testuser"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- lineinfile:
|
- name: ensure unset proxy_password
|
||||||
|
lineinfile:
|
||||||
path: /etc/yum.conf
|
path: /etc/yum.conf
|
||||||
line: "proxy_password=1testpassword"
|
line: "proxy_password=1testpassword"
|
||||||
state: absent
|
state: absent
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue