Skip to content
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
58 changes: 58 additions & 0 deletions ansible/roles/host_setup/tasks/disable_icmp_redirect.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
# Copyright 2024, Rackspace Technology, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Set net.ipv4.conf.all.accept_redirects to 0
ansible.posix.sysctl:
name: net.ipv4.conf.all.accept_redirects
value: 0
sysctl_set: true
become: true

- name: Set net.ipv4.conf.default.accept_redirects to 0
ansible.posix.sysctl:
name: net.ipv4.conf.default.accept_redirects
value: 0
sysctl_set: true
become: true

- name: Set net.ipv4.conf.all.secure_redirects to 0
ansible.posix.sysctl:
name: net.ipv4.conf.all.secure_redirects
value: 0
sysctl_set: true
become: true

- name: Set net.ipv4.conf.default.secure_redirects to 0
ansible.posix.sysctl:
name: net.ipv4.conf.default.secure_redirects
value: 0
sysctl_set: true
become: true

- name: Update /etc/sysctl.conf
ansible.builtin.lineinfile:
path: /etc/sysctl.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
with_items:
- {regexp: '^net.ipv4.conf.all.accept_redirects', line: 'net.ipv4.conf.all.accept_redirects = 0'}
- {regexp: '^net.ipv4.conf.default.accept_redirects', line: 'net.ipv4.conf.default.accept_redirects = 0'}
- {regexp: '^net.ipv4.conf.all.secure_redirects', line: 'net.ipv4.conf.all.secure_redirects = 0'}
- {regexp: '^net.ipv4.conf.default.secure_redirects', line: 'net.ipv4.conf.default.secure_redirects = 0'}
Comment on lines +50 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
with_items:
- {regexp: '^net.ipv4.conf.all.accept_redirects', line: 'net.ipv4.conf.all.accept_redirects = 0'}
- {regexp: '^net.ipv4.conf.default.accept_redirects', line: 'net.ipv4.conf.default.accept_redirects = 0'}
- {regexp: '^net.ipv4.conf.all.secure_redirects', line: 'net.ipv4.conf.all.secure_redirects = 0'}
- {regexp: '^net.ipv4.conf.default.secure_redirects', line: 'net.ipv4.conf.default.secure_redirects = 0'}
loop:
- regexp: '^net.ipv4.conf.all.accept_redirects'
line: 'net.ipv4.conf.all.accept_redirects = 0'
- regexp: '^net.ipv4.conf.default.accept_redirects'
line: 'net.ipv4.conf.default.accept_redirects = 0'
- regexp: '^net.ipv4.conf.all.secure_redirects'
line: 'net.ipv4.conf.all.secure_redirects = 0'
- regexp: '^net.ipv4.conf.default.secure_redirects'
line: 'net.ipv4.conf.default.secure_redirects = 0'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, with the previous use of the ansible.posix.sysctl with sysctl_set these options should already be persistent on the system meaning this task would not be needed. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loop with the separated regexp: and line are easier to read. I'd be happy to test it and update. As for sysctl_set, my understanding from the documentation is that it is the equivalent of sysctl -w which does not appear to write the configuration line to /etc/sysctl.conf. Therefore to ensure the lines were written to the config file, I have been updating the file as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the module will set the valures in the default sysctl file, unless specifically disabled. https://docs.ansible.com/projects/ansible/latest/collections/ansible/posix/sysctl_module.html#parameter-sysctl_file


- name: Apply changes to /etc/sysctl.conf
ansible.builtin.command: sysctl -p /etc/sysctl.conf
become: true
3 changes: 3 additions & 0 deletions ansible/roles/host_setup/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,6 @@

- name: Install RAID controller CLI tools
ansible.builtin.include_tasks: raid_cli_tools.yml

- name: Disable ICMP Redirects
ansible.builtin.include_tasks: disable_icmp_redirect.yml