-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #247 from stackhpc/feat/proxy-nameservers
Support configuring nameservers and proxies
- Loading branch information
Showing
14 changed files
with
170 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# proxy | ||
|
||
Define http/s proxy configuration. | ||
|
||
## Role variables | ||
|
||
- `proxy_http_proxy`: Required. Address of http proxy. E.g. "http://10.1.0.28:3128" for a Squid proxy on default port. | ||
- `proxy_https_proxy`: Optional. Address of https proxy. Default is `{{ proxy_http_proxy }}`. | ||
- `proxy_no_proxy`: Optional. Comma-separated list of addresses not to proxy. Default is to concatenate `inventory_hostname` (for hostnames) and `ansible_host` (for host IPs) for all Ansible hosts. | ||
- `proxy_dnf`: Optional bool. Whether to configure yum/dnf proxying through `proxy_http_proxy`. Default `true`. | ||
- `proxy_systemd`: Optional bool. Whether to give processes started by systemd the above http, https and no_proxy configuration. **NB** Running services will need restarting if this is changed. Default `true`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# proxy_http_proxy: | ||
proxy_https_proxy: "{{ proxy_http_proxy }}" | ||
proxy_no_proxy: "{{ (groups['all'] + hostvars.values() | map(attribute='ansible_host')) | sort | join(',') }}" | ||
proxy_dnf: true | ||
proxy_systemd: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
- name: Define configuration in /etc/environment | ||
tags: proxy | ||
lineinfile: | ||
path: "/etc/environment" | ||
create: yes | ||
owner: root | ||
group: root | ||
mode: o=rw,go=r | ||
state: present | ||
regexp: "{{ item.key }}=.*" | ||
line: "{{ item.key }}={{ item.value }}" | ||
loop: | ||
- key: http_proxy | ||
value: "{{ proxy_http_proxy }}" | ||
- key: https_proxy | ||
value: "{{ proxy_https_proxy }}" | ||
- key: no_proxy | ||
value: "{{ proxy_no_proxy }}" | ||
|
||
- name: Define dnf proxy | ||
ini_file: | ||
path: /etc/dnf/dnf.conf | ||
section: main | ||
option: "proxy" | ||
value: "{{ proxy_http_proxy }}" | ||
no_extra_spaces: true | ||
owner: root | ||
group: root | ||
mode: o=rw,go=r | ||
when: proxy_dnf | bool | ||
|
||
- name: Create systemd configuration directory | ||
file: | ||
path: /etc/systemd/system.conf.d/ | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: ug=rw,o=rX | ||
when: proxy_systemd | bool | ||
|
||
- name: Define proxy configuration for systemd units | ||
community.general.ini_file: | ||
path: /etc/systemd/system.conf.d/90-proxy.conf | ||
section: Manager | ||
option: DefaultEnvironment | ||
value: > | ||
"http_proxy={{ proxy_http_proxy }}" "https_proxy={{ proxy_http_proxy }}" "no_proxy={{ proxy_no_proxy }}" | ||
no_extra_spaces: true | ||
owner: root | ||
group: root | ||
mode: ug=rw,o=r | ||
register: _copy_systemd_proxy | ||
when: proxy_systemd | bool | ||
|
||
- name: Restart systemd | ||
command: systemctl daemon-reexec | ||
when: | ||
- proxy_systemd | bool | ||
- _copy_systemd_proxy.changed | default(false) | ||
|
||
- name: Reset connection to get new /etc/environment | ||
meta: reset_connection | ||
# NB: conditionals not supported |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# resolv_conf | ||
|
||
Template out `/etc/resolv.conf`. | ||
|
||
## Role variables | ||
- `resolv_conf_nameservers`: List of up to 3 nameserver addresses. | ||
|
||
Notes: | ||
- `NetworkManager` (if used) will be prevented from rewriting this file on boot. | ||
- If `/etc/resolv.conf` includes `127.0.0.1` (e.g. due to a FreeIPA server installation), then `resolv_conf_nameservers` is ignored and this role does not change `/etc/resolv.conf` | ||
- For hosts in the `resolv_conf` group, the `/etc/resolv.conf` created with `resolv_conf_nameservers` will | ||
NOT be deleted at the end of Packer image builds. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
resolv_conf_nameservers: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[main] | ||
dns=none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
- name: Read nameservers from /etc/resolv.conf | ||
ansible.builtin.slurp: | ||
src: /etc/resolv.conf | ||
register: _slurp_resolv_conf | ||
|
||
- name: Set nameservers in /etc/resolv.conf | ||
# Might need to set this for freeipa_server host, but freeipa server install | ||
# will then change it to point to 127.0.0.1. | ||
ansible.builtin.template: | ||
src: resolv.conf.j2 | ||
dest: /etc/resolv.conf | ||
owner: root | ||
group: root | ||
mode: u=rw,og=r | ||
when: "'127.0.0.1' not in (_slurp_resolv_conf.content | b64decode)" | ||
|
||
- name: Disable NetworkManager control of resolv.conf | ||
ansible.builtin.copy: | ||
src: NetworkManager-dns-none.conf | ||
dest: /etc/NetworkManager/conf.d/90-dns-none.conf | ||
owner: root | ||
group: root | ||
mode: u=rw,og=r | ||
register: _copy_nm_config | ||
|
||
- name: Reload NetworkManager | ||
ansible.builtin.systemd: | ||
name: NetworkManager | ||
state: reloaded | ||
when: _copy_nm_config.changed | default(false) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Created by slurm appliance ansible/roles/resolv_conf | ||
search {{ openhpc_cluster_name }}.{{ tld }} | ||
|
||
{% for ns in resolv_conf_nameservers[0:3] %} | ||
nameserver {{ ns }} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters