Files
configpolicy/roles/useproxy/tasks/main.yml
Dustin C. Hatch daa59bdba5 r/useproxy: Configure dnf to use proxy
Although running `dnf` from the command line works without explicitly
configuring the proxy, because it inherits the environment variables set
by PAM on login from the user's shell, the `dnf` Ansible module does
not, as it does not inherit those variables.  Thus, we need to
explicitly configure the `proxy` setting in `dnf.conf` in order to be
able to install packages via Ansible.

Since `dnf` does not have separate settings for different protocols
(e.g. HTTP, HTTPS, FTP), we need a way to specify which of the
configured proxies to use if there are multiple.  As such, the
*useproxy* role will attempt to use the value of the `dnf_proxy`
variable, if it is set, falling back to `yum_proxy` and finally
`http_proxy`.  This should cover most situations without any explicit
configuration, but allows flexibility for other cases.
2025-03-29 09:30:08 -05:00

84 lines
1.8 KiB
YAML

- name: ensure environment.d directory exists
file:
path: /etc/environment.d
owner: root
group: root
mode: u=rwx,go=rx
state: directory
tags:
- config
- name: ensure proxy environment variables are set
template:
src: proxy.env.j2
dest: /etc/environment.d/40-proxy.env
owner: root
group: root
mode: u=rw,go=r
tags:
- config
- name: ensure /etc/environment is assembled
assemble:
src: /etc/environment.d
dest: /etc/environment
owner: root
group: root
mode: u=rw,go=r
notify:
- reset connection
tags:
- config
- name: ensure systemd default service drop-in directory exists
file:
path: /etc/systemd/system/service.d
owner: root
group: root
mode: u=rwx,go=rx
state: directory
tags:
- systemd
- name: ensure proxy is configured for systemd services
copy:
dest: /etc/systemd/system/service.d/40-proxy.conf
content: |
[Service]
EnvironmentFile=-/etc/environment.d/40-proxy.env
notify:
- reload systemd
tags:
- systemd
- name: ensure dnf is configured to use proxy
ini_file:
path: /etc/dnf/dnf.conf
section: main
option: proxy
value: '{{ dnf_proxy|d(yum_proxy|d(http_proxy)) }}'
state: present
tags:
- yum
- name: ensure yum repos are configured to use baseurl
ini_file:
path: /etc/yum.repos.d/{{ item.file }}.repo
section: '{{ item.name }}'
option: baseurl
value: '{{ item.baseurl }}'
state: present
loop: '{{ useproxy_yum_repos }}'
tags:
- yum
- name: ensure yum repos are configured to not use metalink
ini_file:
path: /etc/yum.repos.d/{{ item.file }}.repo
section: '{{ item.name }}'
option: metalink
state: absent
loop: '{{ useproxy_yum_repos }}'
tags:
- yum
- name: flush handlers
meta: flush_handlers