Skip to content

Commit

Permalink
adding remove functionality and header
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Leiner committed May 21, 2024
1 parent 4ae0e59 commit 9c4122f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
3 changes: 3 additions & 0 deletions ansible_header.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## This is an Ansible managed file, contents will be overwritten ##

{{ file_contents }}
16 changes: 0 additions & 16 deletions roles/rke2_common/tasks/add-pod-security-admission-config.yml

This file was deleted.

4 changes: 0 additions & 4 deletions roles/rke2_common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@
ansible.builtin.include_tasks: add-registry-config.yml
when: registry_config_file_path | length > 0

- name: Include task file add-pod-security-admission-config.yml
ansible.builtin.include_tasks: add-pod-security-admission-config.yml
when: pod_security_admission_config_file_path | length > 0

- name: Run CIS-Hardening Tasks
ansible.builtin.include_role:
name: rke2_common
Expand Down
45 changes: 45 additions & 0 deletions roles/rke2_server/tasks/add-pod-security-admission-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---

Check failure on line 1 in roles/rke2_server/tasks/add-pod-security-admission-config.yml

View workflow job for this annotation

GitHub Actions / Lint for push

1:4 [new-lines] wrong new line character: expected \n
- name: Create the /etc/rancher/rke2 config dir
ansible.builtin.file:
path: /etc/rancher/rke2
state: directory
recurse: yes

- name: Add pod security admission config file
vars:
file_contents: "{{ lookup('file', pod_security_admission_config_file_path) }}"

Check failure on line 10 in roles/rke2_server/tasks/add-pod-security-admission-config.yml

View workflow job for this annotation

GitHub Actions / Lint for push

10:9 [indentation] wrong indentation: expected 4 but found 8
ansible.builtin.template:
src: ansible_header.j2
dest: "/etc/rancher/rke2/pod-security-admission-config.yaml"
mode: '0640'
owner: root
group: root
when:

Check failure on line 17 in roles/rke2_server/tasks/add-pod-security-admission-config.yml

View workflow job for this annotation

GitHub Actions / Lint for push

17:8 [trailing-spaces] trailing spaces
- pod_security_admission_config_file_path is defined

Check failure on line 18 in roles/rke2_server/tasks/add-pod-security-admission-config.yml

View workflow job for this annotation

GitHub Actions / Lint for push

18:3 [indentation] wrong indentation: expected 4 but found 2
- pod_security_admission_config_file_path|length != 0
notify: Restart rke2-server

- name: Remove pod security admission config file
block:
- name: Check that the PSA config file exists
ansible.builtin.stat:
path: "/etc/rancher/rke2/pod-security-admission-config.yaml"
register: stat_result

- name: "Check that the PSA config file has ansible managed comments"
lineinfile:
name: "/etc/rancher/rke2/pod-security-admission-config.yaml"
line: '## This is an Ansible managed file, contents will be overwritten ##'
state: present
check_mode: yes
register: ansible_managed_check
when: stat_result.stat.exists

- name: Remove the PSA config file if exists and has ansible managed comments
ansible.builtin.file:
path: "/etc/rancher/rke2/pod-security-admission-config.yaml"
state: absent
when:
- ansible_managed_check.changed == false

Check failure on line 43 in roles/rke2_server/tasks/add-pod-security-admission-config.yml

View workflow job for this annotation

GitHub Actions / Lint for push

43:7 [indentation] wrong indentation: expected 8 but found 6
when:
- pod_security_admission_config_file_path is not defined or pod_security_admission_config_file_path|length == 0

Check failure on line 45 in roles/rke2_server/tasks/add-pod-security-admission-config.yml

View workflow job for this annotation

GitHub Actions / Lint for push

45:116 [new-line-at-end-of-file] no new line character at the end of file
3 changes: 3 additions & 0 deletions roles/rke2_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
name: rke2_common
tasks_from: main

- name: Include task file add-pod-security-admission-config.yml
ansible.builtin.include_tasks: add-pod-security-admission-config.yml

- name: Setup initial server
ansible.builtin.include_tasks: first_server.yml
when: inventory_hostname in groups['rke2_servers'][0]
Expand Down

0 comments on commit 9c4122f

Please sign in to comment.