Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for systemd env options #242

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions inventory/sample/group_vars/rke2_agents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ rke2_config: {}
# See https://docs.rke2.io/install/containerd_registry_configuration/
# Add a registry configuration file by specifying the file path on the control host
# registry_config_file_path: "{{ playbook_dir }}/sample_files/registries.yaml"

# See https://docs.rke2.io/advanced#configuring-an-http-proxy
# Add proxy information for the systemd environment
# systemd_extra_env:
# #- HTTP_PROXY=http://your-proxy.example.com:8888
# #- HTTPS_PROXY=http://your-proxy.example.com:8888
# #- NO_PROXY=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
7 changes: 7 additions & 0 deletions inventory/sample/group_vars/rke2_servers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ rke2_config: {}
# Add a pod security admission config file by specifying the file path on the control host
# Requires config.yaml to include `- admission-control-config-file=/etc/rancher/rke2/pod-security-admission-config.yaml` in order for this to be honored
# pod_security_admission_config_file_path: "{{ playbook_dir }}/sample_files/pod-security-admission-config.yaml"

# See https://docs.rke2.io/advanced#configuring-an-http-proxy
# Add proxy information for the systemd environment
# systemd_extra_env:
# #- HTTP_PROXY=http://your-proxy.example.com:8888
# #- HTTPS_PROXY=http://your-proxy.example.com:8888
# #- NO_PROXY=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
2 changes: 2 additions & 0 deletions roles/rke2_common/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
tarball_dir: "/usr/local"

Check warning on line 2 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: tarball_dir)

Check warning on line 2 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: tarball_dir)

Check warning on line 2 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: tarball_dir)
rke2_tarball_url: ""

Check warning on line 3 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_tarball_url)

Check warning on line 3 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_tarball_url)

Check warning on line 3 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_tarball_url)
rke2_images_urls: []

Check warning on line 4 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_images_urls)

Check warning on line 4 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_images_urls)

Check warning on line 4 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_images_urls)
rke2_channel: stable

Check warning on line 5 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_channel)

Check warning on line 5 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_channel)

Check warning on line 5 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: rke2_channel)
audit_policy_config_file_path: ""

Check warning on line 6 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: audit_policy_config_file_path)

Check warning on line 6 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: audit_policy_config_file_path)

Check warning on line 6 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: audit_policy_config_file_path)
registry_config_file_path: ""

Check warning on line 7 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for push

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: registry_config_file_path)

Check warning on line 7 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: registry_config_file_path)

Check warning on line 7 in roles/rke2_common/defaults/main.yml

View workflow job for this annotation

GitHub Actions / Lint for PR

var-naming[no-role-prefix]

Variables names from within roles should use rke2_common_ as a prefix. (vars: registry_config_file_path)
pod_security_admission_config_file_path: ""
add_iptables_rules: false
rke2_common_yum_repo:
Expand All @@ -24,3 +24,5 @@
enabled: yes

rke2_config: {}

systemd_extra_env: {}
2 changes: 2 additions & 0 deletions roles/rke2_common/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
name: systemd-sysctl

- name: Restart rke2-server
throttle: 1
ansible.builtin.service:
state: restarted
name: rke2-server

- name: Restart rke2-agent
throttle: 1
ansible.builtin.service:
state: restarted
name: rke2-agent
59 changes: 59 additions & 0 deletions roles/rke2_common/tasks/add-systemd-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
- name: Add the systemd env file for rke2-{{ rke2_common_caller_role_name }}
when: (systemd_extra_env is defined) and (systemd_extra_env|length > 0)
ansible.builtin.blockinfile:
path: /etc/default/rke2-{{ rke2_common_caller_role_name }}
marker: "#{mark} This is an Ansible managed file, contents will be overwritten"
create: true
mode: '640'
owner: root
group: root
block: |
{% for item in systemd_extra_env %}
{{ item }}
{% endfor %}
register: systemd_added

- name: Remove the systemd env file
when:
- (systemd_extra_env is not defined) or (systemd_extra_env|length == 0)
block:
- name: Check that the systemd env file exists
ansible.builtin.stat:
path: /etc/default/rke2-{{ rke2_common_caller_role_name }}
register: stat_result

- name: "Check that the systemd env file has ansible managed comments"
ansible.builtin.lineinfile:
name: "/etc/default/rke2-{{ rke2_common_caller_role_name }}"
line: '#BEGIN This is an Ansible managed file, contents will be overwritten'
state: present
check_mode: yes
register: ansible_managed_check
when: stat_result.stat.exists | bool is true

- name: Remove the systemd env file if exists and has ansible managed comments
ansible.builtin.file:
path: "/etc/default/rke2-{{ rke2_common_caller_role_name }}"
state: absent
when:
- ansible_managed_check.changed | bool is false
register: systemd_removed

# Reload systemd if adding env file on initial build
- name: Reload the systemd daemon
ansible.builtin.systemd:
daemon_reload: true
when:
- systemd_added is changed
- installed is false

# Reload and restart service if adding/removing env file post install
- name: Reload the systemd daemon and notify restart of rke2-{{ rke2_common_caller_role_name }}
ansible.builtin.systemd:
daemon_reload: true
changed_when: true
notify: Restart rke2-{{ rke2_common_caller_role_name }}
when:
- (systemd_added is changed) or (systemd_removed is changed)
- installed is true
3 changes: 3 additions & 0 deletions roles/rke2_common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
ansible.builtin.include_tasks: add-registry-config.yml
when: registry_config_file_path | length > 0

- name: Include task file add-systemd-env.yml
ansible.builtin.include_tasks: add-systemd-env.yml

- name: Run CIS-Hardening Tasks
ansible.builtin.include_role:
name: rke2_common
Expand Down
Loading