fix(vpn-node-config): resolve ansible-lint violations
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Canceled after 0s
OpenVPN Ansible / Generate SBOM (push) Canceled after 0s
OpenVPN Ansible / Scan SBOM with Trivy (push) Canceled after 0s
OpenVPN Ansible / Ansible Syntax Check (push) Canceled after 38s
OpenVPN Ansible / Ansible Lint (push) Canceled after 40s

This commit is contained in:
2026-11-11 12:13:20 +01:00
parent acb5c4ba82
commit 72fb458dab
3659 changed files with 471307 additions and 12 deletions
@@ -0,0 +1,3 @@
---
collections:
- community.general
@@ -0,0 +1,2 @@
shippable/posix/group1
skip/aix
@@ -0,0 +1,274 @@
---
# (c) 2017, Martin Krizek <mkrizek@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Create ansible user
ansible.builtin.user:
name: "{{ test_user }}"
- name: Create ansible group
ansible.builtin.group:
name: "{{ test_group }}"
- name: Clean up working directory and files
ansible.builtin.file:
path: "{{ output_dir }}"
state: absent
- name: Create working directory
ansible.builtin.file:
path: "{{ output_dir }}"
state: directory
mode: "0755"
- name: Create ansible file
ansible.builtin.file:
path: "{{ test_file }}"
state: touch
mode: "0644"
- name: Create ansible dir
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
mode: "{{ item.mode }}"
loop:
- { path: "{{ test_dir }}", mode: "0755" }
- { path: "{{ test_recursive_dir }}", mode: "0755" }
- name: Install acl package
ansible.builtin.package:
name: acl
state: present
##############################################################################
- name: Grant ansible user read access to a file
ansible.posix.acl:
path: "{{ test_file }}"
entity: "{{ test_user }}"
etype: user
permissions: r
state: present
register: output
- name: Debug ansible.posix.acl output
ansible.builtin.debug:
msg: "{{ output }}"
- name: Get getfacl output
ansible.builtin.command: getfacl {{ test_file | quote }}
changed_when: false
register: getfacl_output
- name: Debug getfacl output
ansible.builtin.debug:
msg: "{{ getfacl_output.stdout_lines }}"
- name: Verify Output
ansible.builtin.assert:
that:
- output is changed
- output is not failed
- "'user:{{ test_user }}:r--' in output.acl"
- "'user:{{ test_user }}:r--' in getfacl_output.stdout_lines"
##############################################################################
- name: Obtain the acl for a specific file
ansible.posix.acl:
path: "{{ test_file }}"
register: output
- name: Debug ansible.posix.acl output
ansible.builtin.debug:
msg: "{{ output }}"
- name: Get getfacl output
ansible.builtin.command: getfacl {{ test_file | quote }}
changed_when: false
register: getfacl_output
- name: Debug getfacl output
ansible.builtin.debug:
msg: "{{ getfacl_output.stdout_lines }}"
- name: Verify output
ansible.builtin.assert:
that:
- output is not changed
- output is not failed
- "'user::rw-' in output.acl"
- "'user:{{ test_user }}:r--' in output.acl"
- "'group::r--' in output.acl"
- "'mask::r--' in output.acl"
- "'other::r--' in output.acl"
- "'user::rw-' in getfacl_output.stdout_lines"
- "'user:{{ test_user }}:r--' in getfacl_output.stdout_lines"
- "'group::r--' in getfacl_output.stdout_lines"
- "'mask::r--' in getfacl_output.stdout_lines"
- "'other::r--' in getfacl_output.stdout_lines"
##############################################################################
#
- name: Removes the acl for ansible user on a specific file
ansible.posix.acl:
path: "{{ test_file }}"
entity: "{{ test_user }}"
etype: user
state: absent
register: output
- name: Get getfacl output
ansible.builtin.command: getfacl {{ test_file | quote }}
changed_when: false
register: getfacl_output
- name: Verify output
ansible.builtin.assert:
that:
- output is changed
- output is not failed
- "'user:{{ test_user }}:r--' not in output.acl"
- "'user:{{ test_user }}:r--' not in getfacl_output.stdout_lines"
##############################################################################
- name: Sets default acl for ansible user on ansible dir
ansible.posix.acl:
path: "{{ test_dir }}"
entity: "{{ test_user }}"
etype: user
permissions: rw
default: true
state: present
register: output
- name: Get getfacl output
ansible.builtin.command: getfacl {{ test_dir | quote }}
changed_when: false
register: getfacl_output
- name: Verify output
ansible.builtin.assert:
that:
- output is changed
- output is not failed
- "'user:{{ test_user }}:rw-' in output.acl"
- "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines"
##############################################################################
- name: Cleanup
ansible.builtin.command: setfacl -b {{ test_dir | quote }}
changed_when: false
##############################################################################
- name: Same as previous but using entry shorthand
ansible.posix.acl:
path: "{{ test_dir }}"
entry: user:{{ test_user }}:rw-
default: true
state: present
register: output
- name: Get getfacl output
ansible.builtin.command: getfacl {{ test_dir | quote }}
changed_when: false
register: getfacl_output
- name: Verify output
ansible.builtin.assert:
that:
- output is changed
- output is not failed
- "'user:{{ test_user }}:rw-' in output.acl"
- "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines"
##############################################################################
- name: Same as previous, to test idempotence
ansible.posix.acl:
path: "{{ test_dir }}"
entry: user:{{ test_user }}:rw-
default: true
state: present
register: output
- name: Get getfacl output
ansible.builtin.command: getfacl {{ test_dir | quote }}
changed_when: false
register: getfacl_output
- name: Verify output
ansible.builtin.assert:
that:
- output is not changed
- output is not failed
- "'user:{{ test_user }}:rw-' in output.acl"
- "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines"
##############################################################################
- name: Cleanup
ansible.builtin.command: setfacl -b {{ test_dir | quote }}
changed_when: false
##############################################################################
- name: Set default acls
ansible.posix.acl:
path: "{{ test_dir }}"
entry: "{{ item }}"
default: true
state: present
with_items:
- user:{{ test_user }}:rw-
- group:{{ test_group }}:rw-
- name: Remove default group test_user acl
ansible.posix.acl:
path: "{{ test_dir }}"
entry: group:{{ test_group }}:rw-
default: true
state: absent
register: output
- name: Get getfacl output
ansible.builtin.command: getfacl {{ test_dir | quote }}
changed_when: false
register: getfacl_output
- name: Verify output
ansible.builtin.assert:
that:
- output is changed
- output is not failed
- "'user::rwx' in getfacl_output.stdout_lines"
- "'group::r-x' in getfacl_output.stdout_lines"
- "'other::r-x' in getfacl_output.stdout_lines"
- "'default:user::rwx' in getfacl_output.stdout_lines"
- "'default:user:{{ test_user }}:rw-' in getfacl_output.stdout_lines"
- "'default:group::r-x' in getfacl_output.stdout_lines"
- "'default:mask::rwx' in getfacl_output.stdout_lines"
- "'default:other::r-x' in getfacl_output.stdout_lines"
- "'default:group:{{ test_group }}:rw-' not in getfacl_output.stdout_lines"
##############################################################################
- name: create file
ansible.builtin.copy:
dest: "{{ test_recursive_dir }}/txt.txt"
mode: '0440'
content: "hw"
- name: Change ACLs recursively
ansible.posix.acl:
path: "{{ test_recursive_dir }}"
entity: "{{ test_user }}"
etype: user
permissions: rX
state: present
recursive: true
register: output_acl_change
- name: Remove ACLs recursively again
ansible.posix.acl:
path: "{{ test_recursive_dir }}"
entity: "{{ test_user }}"
etype: user
permissions: r
state: present
recursive: true
register: output_acl_remove
- assert:
that:
- output_acl_change is changed
- output_acl_change is not failed
- output_acl_remove is changed
- output_acl_remove is not failed
@@ -0,0 +1,23 @@
---
# (c) 2017, Martin Krizek <mkrizek@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Test ACL
vars:
test_user: ansible_user
test_group: ansible_group
test_file: "{{ output_dir }}/ansible file"
test_dir: "{{ output_dir }}/ansible_dir/with some space"
test_recursive_dir: "{{ output_dir }}/recursive_dir"
block:
- name: Include tests task file
ansible.builtin.include_tasks: acl.yml
when: ansible_system == 'Linux' # TODO enable acls mount option on FreeBSD to test it there too
always:
- name: Delete created directory and file
ansible.builtin.file:
path: "{{ item }}"
state: absent
with_items:
- "{{ test_dir }}"
- "{{ test_file }}"
@@ -0,0 +1,3 @@
shippable/posix/group1
destructive
disabled # fixme package
@@ -0,0 +1,3 @@
---
dependencies:
- prepare_tests
@@ -0,0 +1,72 @@
---
# Test code for the at module.
# (c) 2017, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Set output_dir_test fast
ansible.builtin.set_fact:
output_dir_test: "{{ output_dir }}/at"
- name: Make sure our testing sub-directory does not exist
ansible.builtin.file:
path: "{{ output_dir_test }}"
state: absent
- name: Create our testing sub-directory
ansible.builtin.file:
path: "{{ output_dir_test }}"
state: directory
mode: "0755"
##
## at
##
- name: Define distros to attempt installing at on
ansible.builtin.set_fact:
package_distros:
- RedHat
- CentOS
- ScientificLinux
- Fedora
- Ubuntu
- Debian
- openSUSE Leap
- name: Ensure at is installed
ansible.builtin.package:
name: at
state: present
when: ansible_distribution in package_distros
- name: Run the first example
ansible.posix.at:
command: ls -d / > /dev/null
count: 20
units: minutes
register: at_test0
- name: Debug var=at_test0
ansible.builtin.debug:
var: at_test0
- name: Validate results
ansible.builtin.assert:
that:
- at_test0.changed is defined
- at_test0.count is defined
- at_test0.script_file is defined
- at_test0.state is defined
- at_test0.units is defined
@@ -0,0 +1,2 @@
needs/root
shippable/posix/group1
@@ -0,0 +1,39 @@
---
dss_key_basic: ssh-dss DATA_BASIC root@testing
dss_key_unquoted_option: idle-timeout=5m ssh-dss DATA_UNQUOTED_OPTION root@testing
dss_key_command: command="/bin/true" ssh-dss DATA_COMMAND root@testing
dss_key_complex_command: command="echo foo 'bar baz'" ssh-dss DATA_COMPLEX_COMMAND root@testing
dss_key_command_single_option: no-port-forwarding,command="/bin/true" ssh-dss DATA_COMMAND_SINGLE_OPTIONS root@testing
dss_key_command_multiple_options: no-port-forwarding,idle-timeout=5m,command="/bin/true" ssh-dss DATA_COMMAND_MULTIPLE_OPTIONS root@testing
dss_key_trailing: ssh-dss DATA_TRAILING root@testing foo bar baz
rsa_key_basic: ssh-rsa DATA_BASIC root@testing
multiple_key_base: |
ssh-rsa DATA_BASIC 1@testing
ssh-dss DATA_TRAILING 2@testing foo bar baz
ssh-dss DATA_TRAILING 3@testing foo bar baz
ecdsa-sha2-nistp521 ECDSA_DATA 4@testing
multiple_key_different_order: |
ssh-dss DATA_TRAILING 2@testing foo bar baz
ssh-dss DATA_TRAILING 3@testing foo bar baz
ssh-rsa DATA_BASIC 1@testing
ecdsa-sha2-nistp521 ECDSA_DATA 4@testing
multiple_key_different_order_2: |
ssh-dss DATA_TRAILING 2@testing foo bar baz
ssh-rsa WHATEVER 2.5@testing
ssh-dss DATA_TRAILING 3@testing foo bar baz
ssh-rsa DATA_BASIC 1@testing
ecdsa-sha2-nistp521 ECDSA_DATA 4@testing
multiple_key_exclusive: |
ssh-rsa DATA_BASIC 1@testing
ecdsa-sha2-nistp521 ECDSA_DATA 4@testing
multiple_keys_comments: |
ssh-rsa DATA_BASIC 1@testing
# I like adding comments yo-dude-this-is-not-a-key INVALID_DATA 2@testing
ecdsa-sha2-nistp521 ECDSA_DATA 4@testing
key_path: /tmp/id_rsa.pub
@@ -0,0 +1,5 @@
# I like candy
ssh-rsa somekeydata somekeyalias
# It is a very pleasant temperature outside today.
ssh-rsa otherkeydata otherkeyalias
@@ -0,0 +1,3 @@
---
dependencies:
- prepare_tests
@@ -0,0 +1,37 @@
---
# -------------------------------------------------------------
# check mode
- name: CHECK MODE | copy an existing file in place with comments
ansible.builtin.copy:
src: existing_authorized_keys
dest: "{{ output_dir | expanduser }}/authorized_keys"
mode: "0600"
- name: CHECK MODE | add key in check mode to validate return codes
ansible.posix.authorized_key:
user: root
key: "{{ multiple_key_different_order_2 }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
check_mode: true
register: result
- name: CHECK MODE | assert that authorized_keys return values are consistent
ansible.builtin.assert:
that:
- result.changed == True
- '"user" in result'
- '"key" in result'
- name: CHECK MODE | recopy authorized_keys to ensure it was not changed
ansible.builtin.copy:
src: existing_authorized_keys
dest: "{{ output_dir | expanduser }}/authorized_keys"
mode: "0600"
register: result
- name: CHECK MODE | assert that the authorized_keys file was not changed
ansible.builtin.assert:
that:
- result.changed == False
@@ -0,0 +1,32 @@
---
- name: Create key file for test
ansible.builtin.copy:
dest: "{{ key_path }}"
content: "{{ rsa_key_basic }}"
mode: "0600"
- name: Add key using path
ansible.posix.authorized_key:
user: root
key: file://{{ key_path }}
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == true
- name: Add key using path again
ansible.posix.authorized_key:
user: root
key: file://{{ key_path }}
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that no changes were applied
ansible.builtin.assert:
that:
- result.changed == false
@@ -0,0 +1,41 @@
---
# -------------------------------------------------------------
# check permissions
- name: Create a file that is not accessible
ansible.builtin.file:
state: touch
path: "{{ output_dir | expanduser }}/file_permissions"
owner: root
mode: '0000'
- name: Create unprivileged user
ansible.builtin.user:
name: nopriv
create_home: true
- name: Try to delete a key from an unreadable file
become: true
become_user: nopriv
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_basic }}"
state: absent
path: "{{ output_dir | expanduser }}/file_permissions"
register: result
ignore_errors: true
- name: Assert that the key deletion has failed
ansible.builtin.assert:
that:
- result is failed
- name: Remove the file
ansible.builtin.file:
state: absent
path: "{{ output_dir | expanduser }}/file_permissions"
- name: Remove the user
ansible.builtin.user:
name: nopriv
state: absent
@@ -0,0 +1,22 @@
---
#
# Check: keysfile is symlink and follow=false
#
- name: Try to add key with keysfile as symlink
ansible.posix.authorized_key:
user: testuser
key: "{{ rsa_key_basic }}"
state: present
manage_dir: false
follow: false
- name: Assert target file ownership unchanged
ansible.builtin.stat:
path: /tmp/symlink_test_target/target_file
register: target_file_stat
- name: Verify target file is still owned by root
ansible.builtin.assert:
that:
- target_file_stat.stat.uid == 0
...
@@ -0,0 +1,12 @@
---
- name: Remove testuser
ansible.builtin.user:
name: testuser
state: absent
remove: true
- name: Remove symlink target directory
ansible.builtin.file:
path: /tmp/symlink_test_target
state: absent
...
@@ -0,0 +1,38 @@
---
- name: Create testuser for symlink tests
ansible.builtin.user:
name: testuser
create_home: true
register: testuser_result
- name: Create symlink target directory
ansible.builtin.file:
path: /tmp/symlink_test_target
state: directory
owner: root
mode: '0700'
- name: Create a target file owned by root
ansible.builtin.copy:
dest: /tmp/symlink_test_target/target_file
content: "sensitive data"
owner: root
mode: '0600'
- name: Remove .ssh directory if exists
ansible.builtin.file:
path: "{{ testuser_result.home }}/.ssh"
state: absent
- name: Create .ssh directory
ansible.builtin.file:
path: "{{ testuser_result.home }}/.ssh"
state: directory
mode: '0700'
- name: Create symlink from authorized_keys to target file
ansible.builtin.file:
src: /tmp/symlink_test_target/target_file
dest: "{{ testuser_result.home }}/.ssh/authorized_keys"
state: link
...
@@ -0,0 +1,52 @@
---
# -------------------------------------------------------------
# comments
- name: Add rsa key with existing comment
ansible.posix.authorized_key:
user: root
key: "{{ rsa_key_basic }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Change the comment on an existing key
ansible.posix.authorized_key:
user: root
key: "{{ rsa_key_basic }}"
comment: user@acme.com
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Get the file content
ansible.builtin.command: fgrep DATA_BASIC "{{ output_dir | expanduser }}/authorized_keys"
changed_when: false
register: content
- name: Assert that comment on an existing key was changed
ansible.builtin.assert:
that:
- "'user@acme.com' in content.stdout"
- name: Set the same key with comment to ensure no changes are reported
ansible.posix.authorized_key:
user: root
key: "{{ rsa_key_basic }}"
comment: user@acme.com
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that no changes were made when running again
ansible.builtin.assert:
that:
- not result.changed
- name: Debug the result and content
ansible.builtin.debug:
var: "{{ item }}"
verbosity: 1
with_items:
- result
- content
@@ -0,0 +1,48 @@
---
# test code for the authorized_key module
# - (c) 2014, James Cammarata <jcammarata@ansible.com>
# - (c) 2021, Hideki Saito <saito@fgrep.org>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Setup for testing environment
ansible.builtin.import_tasks: setup_steps.yml
- name: Test for multiple keys handling
ansible.builtin.import_tasks: multiple_keys.yml
- name: Test for ssh-dss key handling
ansible.builtin.import_tasks: ssh_dss.yml
- name: Test for check mode
ansible.builtin.import_tasks: check_mode.yml
- name: Test for the management of comments with key
ansible.builtin.import_tasks: comments.yml
- name: Test for specifying key as a path
ansible.builtin.import_tasks: check_path.yml
- name: Test for permission denied files
ansible.builtin.import_tasks: check_permissions.yml
- name: CVE-2026-11837 Setup for symlink tests
ansible.builtin.import_tasks: check_symlink_setup.yml
- name: CVE-2026-11837 Test for symlink tests
ansible.builtin.import_tasks: check_symlink.yml
- name: CVE-2026-11837 Cleanup symlink test
ansible.builtin.import_tasks: check_symlink_cleanup.yml
@@ -0,0 +1,97 @@
---
# -------------------------------------------------------------
# multiple keys
- name: Add multiple keys
ansible.posix.authorized_key:
user: root
key: "{{ multiple_key_base }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == multiple_key_base
- result.key_options == None
- name: Add multiple keys different order
ansible.posix.authorized_key:
user: root
key: "{{ multiple_key_different_order }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == multiple_key_different_order
- result.key_options == None
- name: Add multiple keys exclusive
ansible.posix.authorized_key:
user: root
key: "{{ multiple_key_exclusive }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
exclusive: true
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == multiple_key_exclusive
- result.key_options == None
- name: Add multiple keys in different calls
ansible.posix.authorized_key:
user: root
key: ecdsa-sha2-nistp521 ECDSA_DATA 4@testing
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Add multiple keys in different calls
ansible.posix.authorized_key:
user: root
key: ssh-rsa DATA_BASIC 1@testing
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Get the file content
ansible.builtin.command: /bin/cat "{{ output_dir | expanduser }}/authorized_keys"
changed_when: false
register: multiple_keys_at_a_time
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == false
- multiple_keys_at_a_time.stdout == multiple_key_exclusive.strip()
- name: Add multiple keys comment
ansible.posix.authorized_key:
user: root
key: "{{ multiple_keys_comments }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
exclusive: true
register: result
- name: Get the file content
ansible.builtin.command: /bin/cat "{{ output_dir | expanduser }}/authorized_keys"
changed_when: false
register: multiple_keys_comments
- name: Assert that the keys exist and comment only lines were not added
ansible.builtin.assert:
that:
- result.changed == False
- multiple_keys_comments.stdout == multiple_key_exclusive.strip()
- result.key_options == None
@@ -0,0 +1,63 @@
---
# -------------------------------------------------------------
# Setup steps
- name: Clean up the working directory and files
ansible.builtin.file:
path: "{{ output_dir }}"
state: absent
- name: Create the working directory
ansible.builtin.file:
path: "{{ output_dir }}"
state: directory
mode: "0744"
- name: Copy an existing file in place with comments
ansible.builtin.copy:
src: existing_authorized_keys
dest: "{{ output_dir | expanduser }}/authorized_keys"
mode: "0600"
- name: Add multiple keys different order
ansible.posix.authorized_key:
user: root
key: "{{ multiple_key_different_order_2 }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Get the file content
ansible.builtin.command: /bin/cat "{{ output_dir | expanduser }}/authorized_keys"
changed_when: false
register: multiple_keys_existing
- name: Assert that the key was added and comments and ordering preserved
ansible.builtin.assert:
that:
- result.changed == True
- '"# I like candy" in multiple_keys_existing.stdout'
- '"# I like candy" in multiple_keys_existing.stdout_lines[0]'
- '"ssh-rsa DATA_BASIC 1@testing" in multiple_keys_existing.stdout'
# The specific index is a little fragile, but I want to verify the line shows up
# as the 3rd line in the new entries after the existing entries and comments are preserved
- '"ssh-rsa DATA_BASIC 1@testing" in multiple_keys_existing.stdout_lines[7]'
# start afresh
- name: Remove file foo.txt
ansible.builtin.file:
path: "{{ output_dir | expanduser }}/authorized_keys"
state: absent
- name: Touch the authorized_keys file
ansible.builtin.file:
dest: "{{ output_dir }}/authorized_keys"
state: touch
mode: "0600"
register: result
- name: Assert that the authorized_keys file was created
ansible.builtin.assert:
that:
- result.changed == True
- result.state == "file"
@@ -0,0 +1,250 @@
---
# -------------------------------------------------------------
# basic ssh-dss key
- name: Add basic ssh-dss key
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_basic }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == dss_key_basic
- result.key_options == None
- name: Re-add basic ssh-dss key
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_basic }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that nothing changed
ansible.builtin.assert:
that:
- result.changed == False
# -------------------------------------------------------------
# ssh-dss key with an unquoted option
- name: Add ssh-dss key with an unquoted option
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_unquoted_option }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == dss_key_unquoted_option
- result.key_options == None
- name: Re-add ssh-dss key with an unquoted option
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_unquoted_option }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that nothing changed
ansible.builtin.assert:
that:
- result.changed == False
# -------------------------------------------------------------
# ssh-dss key with a leading command="/bin/foo"
- name: Add ssh-dss key with a leading command
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_command }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == dss_key_command
- result.key_options == None
- name: Re-add ssh-dss key with a leading command
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_command }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that nothing changed
ansible.builtin.assert:
that:
- result.changed == False
# -------------------------------------------------------------
# ssh-dss key with a complex quoted leading command
# ie. command="/bin/echo foo 'bar baz'"
- name: Add ssh-dss key with a complex quoted leading command
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_complex_command }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == dss_key_complex_command
- result.key_options == None
- name: Re-add ssh-dss key with a complex quoted leading command
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_complex_command }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that nothing changed
ansible.builtin.assert:
that:
- result.changed == False
# -------------------------------------------------------------
# ssh-dss key with a command and a single option, which are
# in a comma-separated list
- name: Add ssh-dss key with a command and a single option
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_command_single_option }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == dss_key_command_single_option
- result.key_options == None
- name: Re-add ssh-dss key with a command and a single option
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_command_single_option }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that nothing changed
ansible.builtin.assert:
that:
- result.changed == False
# -------------------------------------------------------------
# ssh-dss key with a command and multiple other options
- name: Add ssh-dss key with a command and multiple options
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_command_multiple_options }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == dss_key_command_multiple_options
- result.key_options == None
- name: Re-add ssh-dss key with a command and multiple options
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_command_multiple_options }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that nothing changed
ansible.builtin.assert:
that:
- result.changed == False
# -------------------------------------------------------------
# ssh-dss key with multiple trailing parts, which are space-
# separated and not quoted in any way
- name: Add ssh-dss key with trailing parts
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_trailing }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == dss_key_trailing
- result.key_options == None
- name: Re-add ssh-dss key with trailing parts
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_trailing }}"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that nothing changed
ansible.builtin.assert:
that:
- result.changed == False
# -------------------------------------------------------------
# basic ssh-dss key with mutliple permit-open options
# https://github.com/ansible/ansible-modules-core/issues/1715
- name: Add basic ssh-dss key with multi-opts
ansible.posix.authorized_key:
user: root
key: "{{ dss_key_basic }}"
key_options: no-agent-forwarding,no-X11-forwarding,permitopen="10.9.8.1:8080",permitopen="10.9.8.1:9001"
state: present
path: "{{ output_dir | expanduser }}/authorized_keys"
register: result
- name: Assert that the key with multi-opts was added
ansible.builtin.assert:
that:
- result.changed == True
- result.key == dss_key_basic
- result.key_options == "no-agent-forwarding,no-X11-forwarding,permitopen=\"10.9.8.1:8080\",permitopen=\"10.9.8.1:9001\""
- name: Get the file content
ansible.builtin.command: fgrep DATA_BASIC "{{ output_dir | expanduser }}/authorized_keys"
changed_when: false
register: content
- name: Validate content
ansible.builtin.assert:
that:
- content.stdout == "no-agent-forwarding,no-X11-forwarding,permitopen=\"10.9.8.1:8080\",permitopen=\"10.9.8.1:9001\" ssh-dss DATA_BASIC root@testing"
@@ -0,0 +1,7 @@
needs/privileged
needs/root
destructive
shippable/posix/group1
skip/aix
skip/freebsd
skip/osx
@@ -0,0 +1,3 @@
---
dependencies:
- setup_pkg_mgr
@@ -0,0 +1,116 @@
---
# Test playbook for the firewalld module - icmp block inversion operations
# (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Icmp block inversion enabled when icmp block inversion is truthy and state is enabled
block:
- name: Testing enable icmp block inversion
ansible.posix.firewalld:
zone: trusted
icmp_block_inversion: true
permanent: true
state: enabled
register: result
- name: Assert icmp block inversion is enabled
ansible.builtin.assert:
that:
- result is changed
- name: Testing enable icmp block inversion (verify not changed)
ansible.posix.firewalld:
zone: trusted
icmp_block_inversion: true
permanent: true
state: enabled
register: result
- name: Assert icmp block inversion is enabled (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Icmp block inversion disabled when icmp block inversion is falsy and state is enabled
block:
- name: Testing disable icmp block inversion
ansible.posix.firewalld:
zone: trusted
icmp_block_inversion: false
permanent: true
state: enabled
register: result
- name: Assert icmp block inversion is disabled
ansible.builtin.assert:
that:
- result is changed
- name: Testing disable icmp block inversion (verify not changed)
ansible.posix.firewalld:
zone: trusted
icmp_block_inversion: false
permanent: true
state: enabled
register: result
- name: Assert icmp block inversion is disabled (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Icmp block inversion enabled when icmp block inversion is falsy and state is disabled
block:
- name: Testing enable icmp block inversion
ansible.posix.firewalld:
zone: trusted
icmp_block_inversion: false
permanent: true
state: disabled
register: result
- name: Assert icmp block inversion is enabled
ansible.builtin.assert:
that:
- result is changed
- name: Testing enable icmp block inversion (verify not changed)
ansible.posix.firewalld:
zone: trusted
icmp_block_inversion: false
permanent: true
state: disabled
register: result
- name: Assert icmp block inversion is enabled (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Icmp block inversion disabled when icmp block inversion is truthy and state is disabled
block:
- name: Testing disable icmp block inversion
ansible.posix.firewalld:
zone: trusted
icmp_block_inversion: true
permanent: true
state: disabled
register: result
- name: Assert icmp block inversion is disabled
ansible.builtin.assert:
that:
- result is changed
- name: Testing disable icmp block inversion (verify not changed)
ansible.posix.firewalld:
zone: trusted
icmp_block_inversion: true
permanent: true
state: disabled
register: result
- name: Assert icmp block inversion is disabled (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,88 @@
---
# Test playbook for the firewalld module - interface operations
# (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Validate adding interface
block:
- name: Add lo interface to trusted zone
ansible.posix.firewalld:
interface: lo
zone: trusted
permanent: true
state: enabled
register: result
- name: Assert lo was added to trusted zone
ansible.builtin.assert:
that:
- result is changed
- name: Add lo interface to trusted zone (verify not changed)
ansible.posix.firewalld:
interface: lo
zone: trusted
permanent: true
state: enabled
register: result
- name: Assert lo was added to trusted zone (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Validate moving interfaces
block:
- name: Move lo interface from trusted zone to internal zone
ansible.posix.firewalld:
interface: lo
zone: internal
permanent: true
state: enabled
register: result
- name: Assert lo was moved from trusted zone to internal zone
ansible.builtin.assert:
that:
- result is changed
- name: Move lo interface from trusted zone to internal zone (verify not changed)
ansible.posix.firewalld:
interface: lo
zone: internal
permanent: true
state: enabled
register: result
- name: Assert lo was moved from trusted zone to internal zone (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Validate removing interface
block:
- name: Remove lo interface from internal zone
ansible.posix.firewalld:
interface: lo
zone: internal
permanent: true
state: disabled
register: result
- name: Assert lo interface was removed from internal zone
ansible.builtin.assert:
that:
- result is changed
- name: Remove lo interface from internal zone (verify not changed)
ansible.posix.firewalld:
interface: lo
zone: internal
permanent: true
state: disabled
register: result
- name: Assert lo interface was removed from internal zone (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,45 @@
---
# Test playbook for the firewalld module
# (c) 2017, Adam Miller <admiller@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Run firewalld tests
when:
- ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version is version('7', '>=')
- not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('14.04', '=='))
# Firewalld package on OpenSUSE (15+) require Python 3, so we skip on OpenSUSE running py2 on these newer distros
- not (ansible_os_family == "Suse" and ansible_distribution_major_version|int != 42 and ansible_python.version.major != 3)
- not (ansible_facts.distribution == "CentOS" and ansible_distribution_major_version is version('7', '==')) # FIXME
block:
- name: Ensure firewalld is installed
ansible.builtin.package:
name: firewalld
state: present
# This doesn't work for CentOS 6 because firewalld doesn't exist in CentOS6
- name: Enable dbus-broker daemon
ansible.builtin.service:
name: dbus-broker
enabled: true
state: started
when: (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('34', '=='))
- name: Test Online Operations
block:
- name: Start firewalld
ansible.builtin.service:
name: firewalld
state: started
- name: Import test tasks
ansible.builtin.import_tasks: run_all_tests.yml
- name: Test Offline Operations
block:
- name: Stop firewalld
ansible.builtin.service:
name: firewalld
state: stopped
- name: Import test tasks
ansible.builtin.import_tasks: run_all_tests.yml
@@ -0,0 +1,116 @@
---
# Test playbook for the firewalld module - masquerade operations
# (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Masquerade enabled when masquerade is truthy and state is enabled
block:
- name: Testing enable masquerade
ansible.posix.firewalld:
zone: trusted
masquerade: true
permanent: true
state: enabled
register: result
- name: Assert masquerade is enabled
ansible.builtin.assert:
that:
- result is changed
- name: Testing enable masquerade (verify not changed)
ansible.posix.firewalld:
zone: trusted
masquerade: true
permanent: true
state: enabled
register: result
- name: Assert masquerade is enabled (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Masquerade disabled when masquerade is falsy and state is enabled
block:
- name: Testing disable masquerade
ansible.posix.firewalld:
zone: trusted
masquerade: false
permanent: true
state: enabled
register: result
- name: Assert masquerade is disabled
ansible.builtin.assert:
that:
- result is changed
- name: Testing disable masquerade (verify not changed)
ansible.posix.firewalld:
zone: trusted
masquerade: false
permanent: true
state: enabled
register: result
- name: Assert masquerade is disabled (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Masquerade enabled when masquerade is falsy and state is disabled
block:
- name: Testing enable masquerade
ansible.posix.firewalld:
zone: trusted
masquerade: false
permanent: true
state: disabled
register: result
- name: Assert masquerade is enabled
ansible.builtin.assert:
that:
- result is changed
- name: Testing enable masquerade (verify not changed)
ansible.posix.firewalld:
zone: trusted
masquerade: false
permanent: true
state: disabled
register: result
- name: Assert masquerade is enabled (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Masquerade disabled when masquerade is truthy and state is disabled
block:
- name: Testing disable masquerade
ansible.posix.firewalld:
zone: trusted
masquerade: true
permanent: true
state: disabled
register: result
- name: Assert masquerade is disabled
ansible.builtin.assert:
that:
- result is changed
- name: Testing disable masquerade (verify not changed)
ansible.posix.firewalld:
zone: trusted
masquerade: true
permanent: true
state: disabled
register: result
- name: Assert masquerade is disabled (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,64 @@
---
# Test playbook for the firewalld module - port operations
# (c) 2017, Adam Miller <admiller@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Firewalld port forward test permanent enabled
ansible.posix.firewalld:
port_forward:
- port: 8080
proto: tcp
toport: 8081
permanent: true
state: enabled
register: result
- name: Assert firewalld port test permanent enabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld port test permanent enabled rerun (verify not changed)
ansible.posix.firewalld:
port_forward:
- port: 8080
proto: tcp
toport: 8081
permanent: true
state: enabled
register: result
- name: Assert firewalld port test permanent enabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld port test permanent disabled
ansible.posix.firewalld:
port_forward:
- port: 8080
proto: tcp
toport: 8081
permanent: true
state: disabled
register: result
- name: Assert firewalld port test permanent disabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld port test permanent disabled rerun (verify not changed)
ansible.posix.firewalld:
port_forward:
- port: 8080
proto: tcp
toport: 8081
permanent: true
state: disabled
register: result
- name: Assert firewalld port test permanent disabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,109 @@
---
# Test playbook for the firewalld module - port operations
# (c) 2017, Adam Miller <admiller@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Firewalld port range test permanent enabled
ansible.posix.firewalld:
port: 5500-6850/tcp
permanent: true
state: enabled
register: result
- name: Assert firewalld port range test permanent enabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld port range test permanent enabled rerun (verify not changed)
ansible.posix.firewalld:
port: 5500-6850/tcp
permanent: true
state: enabled
register: result
- name: Assert firewalld port range test permanent enabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld port test permanent enabled
ansible.posix.firewalld:
port: 6900/tcp
permanent: true
state: enabled
register: result
- name: Assert firewalld port test permanent enabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld port test permanent enabled
ansible.posix.firewalld:
port: 6900/tcp
permanent: true
state: enabled
register: result
- name: Assert firewalld port test permanent enabled worked
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld port test disabled
ansible.posix.firewalld:
port: "{{ item }}"
permanent: true
state: disabled
loop:
- 6900/tcp
- 5500-6850/tcp
- name: Firewalld port test permanent enabled
ansible.posix.firewalld:
port: 8081/tcp
permanent: true
state: enabled
register: result
- name: Assert firewalld port test permanent enabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld port test permanent enabled rerun (verify not changed)
ansible.posix.firewalld:
port: 8081/tcp
permanent: true
state: enabled
register: result
- name: Assert firewalld port test permanent enabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld port test permanent disabled
ansible.posix.firewalld:
port: 8081/tcp
permanent: true
state: disabled
register: result
- name: Assert firewalld port test permanent disabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld port test permanent disabled rerun (verify not changed)
ansible.posix.firewalld:
port: 8081/tcp
permanent: true
state: disabled
register: result
- name: Assert firewalld port test permanent disabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,66 @@
---
# Test playbook for the firewalld module - protocol operations
# (c) 2022, Robért S. Guhr <rguhr@cronon.net>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Firewalld protocol test permanent enabled
ansible.posix.firewalld:
protocol: ospf
permanent: true
state: enabled
register: result
- name: Assert firewalld protocol test permanent enabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld protocol test permanent enabled rerun (verify not changed)
ansible.posix.firewalld:
protocol: ospf
permanent: true
state: enabled
register: result
- name: Assert firewalld protocol test permanent enabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld protocol test permanent disabled
ansible.posix.firewalld:
protocol: ospf
permanent: true
state: disabled
register: result
- name: Assert firewalld protocol test permanent disabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld protocol test permanent disabled rerun (verify not changed)
ansible.posix.firewalld:
protocol: ospf
permanent: true
state: disabled
register: result
- name: Assert firewalld protocol test permanent disabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,50 @@
---
# Test playbook for the firewalld module
# (c) 2017, Adam Miller <admiller@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Ensure /run/firewalld exists
ansible.builtin.file:
path: /run/firewalld
state: directory
mode: "0755"
# firewalld service operation test cases
- name: Include service test cases for firewalld module
ansible.builtin.include_tasks: service_test_cases.yml
# firewalld protocol operation test cases
- name: Include protocol test cases for firewalld module
ansible.builtin.include_tasks: protocol_test_cases.yml
# firewalld port operation test cases
- name: Include port test cases for firewalld module
ansible.builtin.include_tasks: port_test_cases.yml
# firewalld source operation test cases
- name: Include source test cases for firewalld module
ansible.builtin.include_tasks: source_test_cases.yml
# firewalld zone operation test cases
- name: Include zone test cases for firewalld module
ansible.builtin.include_tasks: zone_test_cases.yml
# firewalld zone target operation test cases
- name: Include zone target test cases for firewalld module
ansible.builtin.include_tasks: zone_target_test_cases.yml
# firewalld port forwarding operation test cases
- name: Include port forward target test cases for firewalld module
ansible.builtin.include_tasks: port_forward_test_cases.yml
# firewalld masquerade operation test cases
- name: Include masquerade target test cases for firewalld module
ansible.builtin.include_tasks: masquerade_test_cases.yml
# firewalld icmp block inversion operation test cases
- name: Include icmp block inversion target test cases for firewalld module
ansible.builtin.include_tasks: icmp_block_inversion_test_cases.yml
# firewalld interface operation test cases
- name: Include interface target test cases for firewalld module
ansible.builtin.include_tasks: interface_test_cases.yml
@@ -0,0 +1,74 @@
---
# Test playbook for the firewalld module - service operations
# (c) 2017, Adam Miller <admiller@redhat.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Firewalld service test permanent enabled
ansible.posix.firewalld:
service: https
permanent: true
immediate: true
offline: true
state: enabled
register: result
- name: Assert firewalld service test permanent enabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld service test permanent enabled rerun (verify not changed)
ansible.posix.firewalld:
service: https
permanent: true
immediate: true
offline: true
state: enabled
register: result
- name: Assert firewalld service test permanent enabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld service test permanent disabled
ansible.posix.firewalld:
service: https
permanent: true
immediate: true
offline: true
state: disabled
register: result
- name: Assert firewalld service test permanent disabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld service test permanent disabled rerun (verify not changed)
ansible.posix.firewalld:
service: https
permanent: true
immediate: true
offline: true
state: disabled
register: result
- name: Assert firewalld service test permanent disabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,88 @@
---
# Test playbook for the firewalld module - source operations
# (c) 2019, Hideki Saito <saito@fgrep.org>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Firewalld source test permanent enabled
ansible.posix.firewalld:
source: 192.0.2.0/24
zone: internal
permanent: true
state: enabled
register: result
- name: Assert firewalld source test permanent enabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld source test permanent enabled rerun (verify not changed)
ansible.posix.firewalld:
source: 192.0.2.0/24
zone: internal
permanent: true
state: enabled
register: result
- name: Assert firewalld source test permanent enabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld source test permanent disabled
ansible.posix.firewalld:
source: 192.0.2.0/24
zone: internal
permanent: true
state: disabled
register: result
- name: Assert firewalld source test permanent disabled worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld source test permanent disabled rerun (verify not changed)
ansible.posix.firewalld:
source: 192.0.2.0/24
zone: internal
permanent: true
state: disabled
register: result
- name: Assert firewalld source test permanent disabled rerun worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld source test permanent enabled is exclusive (verify exclusive error)
ansible.posix.firewalld:
source: 192.0.2.0/24
port: 8081/tcp
zone: internal
permanent: true
state: enabled
register: result
ignore_errors: true
- name: Assert firewalld source test permanent enabled is exclusive (verify exclusive error)
ansible.builtin.assert:
that:
- result is not changed
- >
result.msg == 'parameters are mutually exclusive:
icmp_block|icmp_block_inversion|service|protocol|port|port_forward|rich_rule|interface|forward|masquerade|source|target'
@@ -0,0 +1,122 @@
---
# Test playbook for the firewalld module - source operations
# (c) 2020, Adam Miller <admiller@redhat.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Firewalld dmz zone target DROP
ansible.posix.firewalld:
zone: dmz
permanent: true
state: present
target: DROP
register: result
- name: Assert firewalld dmz zone target DROP present worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld dmz zone target DROP rerun (verify not changed)
ansible.posix.firewalld:
zone: dmz
permanent: true
state: present
target: DROP
register: result
- name: Assert firewalld dmz zone target DROP present worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld dmz zone target DROP absent
ansible.posix.firewalld:
zone: dmz
permanent: true
state: absent
target: DROP
register: result
- name: Assert firewalld dmz zone target DROP absent worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld dmz zone target DROP rerun (verify not changed)
ansible.posix.firewalld:
zone: dmz
permanent: true
state: absent
target: DROP
register: result
- name: Assert firewalld dmz zone target DROP present worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld dmz zone target %%REJECT%%
ansible.posix.firewalld:
zone: dmz
permanent: true
state: present
target: "%%REJECT%%"
register: result
- name: Assert firewalld dmz zone target %%REJECT%% present worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld dmz zone target %%REJECT%% rerun (verify not changed)
ansible.posix.firewalld:
zone: dmz
permanent: true
state: present
target: "%%REJECT%%"
register: result
- name: Assert firewalld dmz zone target %%REJECT%% present worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Firewalld dmz zone target %%REJECT%% absent
ansible.posix.firewalld:
zone: dmz
permanent: true
state: absent
target: "%%REJECT%%"
register: result
- name: Assert firewalld dmz zone target %%REJECT%% absent worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld dmz zone target %%REJECT%% rerun (verify not changed)
ansible.posix.firewalld:
zone: dmz
permanent: true
state: absent
target: "%%REJECT%%"
register: result
- name: Assert firewalld dmz zone target %%REJECT%% present worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,97 @@
---
- name: Firewalld create zone custom
ansible.posix.firewalld:
zone: custom
permanent: true
state: present
register: result
- name: Assert firewalld custom zone created worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld create zone custom rerun (verify not changed)
ansible.posix.firewalld:
zone: custom
permanent: true
state: present
register: result
- name: Assert firewalld custom zone created worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
- name: Zone forwarding test
when: (ansible_distribution == 'RedHat' and ansible_distribution_major_version is version('8', '>='))
block:
- name: Enable zone forwarding
ansible.posix.firewalld:
zone: custom
forward: true
permanent: true
state: enabled
register: result
- name: Assert zone forwarding is enabled
ansible.builtin.debug:
var: result is changed
- name: Enable zone forwarding (verify not changed)
ansible.posix.firewalld:
zone: custom
forward: true
permanent: true
state: enabled
register: result
- name: Assert zone forwarding is enabled (verify not changed)
ansible.builtin.debug:
var: result is not changed
- name: Disable zone forwarding
ansible.posix.firewalld:
zone: custom
forward: false
permanent: true
state: enabled
- name: Assert zone forwarding is disabled
ansible.builtin.debug:
var: result is changed
- name: Disable zone forwarding (verify not changed)
ansible.posix.firewalld:
zone: custom
forward: false
permanent: true
state: enabled
- name: Assert zone forwarding is disabled (verify not changed)
ansible.builtin.debug:
var: result is not changed
- name: Firewalld remove zone custom
ansible.posix.firewalld:
zone: custom
permanent: true
state: absent
register: result
- name: Assert firewalld custom zone removed worked
ansible.builtin.assert:
that:
- result is changed
- name: Firewalld remove custom zone rerun (verify not changed)
ansible.posix.firewalld:
zone: custom
permanent: true
state: absent
register: result
- name: Assert firewalld custom zone removed worked (verify not changed)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,5 @@
destructive
shippable/posix/group3
skip/aix
skip/freebsd
skip/osx
@@ -0,0 +1,53 @@
---
# Test playbook for the firewalld_info module
# (c) 2021, Hideki Saito <saito@fgrep.org>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# This test is based on the integration test playbook for firewalld module.
- name: Run firewalld tests
when:
- ansible_facts.os_family == "RedHat" and ansible_facts.distribution_major_version is version('7', '>=')
- not (ansible_distribution == "Ubuntu" and ansible_distribution_version is version('14.04', '=='))
# Firewalld package on OpenSUSE (15+) require Python 3, so we skip on OpenSUSE running py2 on these newer distros
- not (ansible_os_family == "Suse" and ansible_distribution_major_version|int != 42 and ansible_python.version.major != 3)
block:
- name: Ensure firewalld is installed
ansible.builtin.package:
name: firewalld
state: present
# This doesn't work for CentOS 6 because firewalld doesn't exist in CentOS6
- name: Check to make sure the firewalld python module is available.
ansible.builtin.command: "{{ ansible_python.executable }} -c 'import firewall'"
changed_when: false
register: check_output_firewall
ignore_errors: true
- name: Check to make sure the dbus python module is available.
ansible.builtin.command: "{{ ansible_python.executable }} -c 'import dbus'"
changed_when: false
register: check_output_dbus
ignore_errors: true
- name: Test Online Operations
block:
- name: Start firewalld
ansible.builtin.service:
name: firewalld
state: started
- name: Import test tasks from run_tests_in_started.yml
ansible.builtin.import_tasks: run_tests_in_started.yml
- name: Test Offline Operations
when:
- check_output_firewall.rc == 0
- check_output_dbus.rc == 0
block:
- name: Stop firewalld
ansible.builtin.service:
name: firewalld
state: stopped
- name: Import test tasks from run_tests_in_stopped.yml
ansible.builtin.import_tasks: run_tests_in_stopped.yml
@@ -0,0 +1,37 @@
---
# Test playbook for the firewalld_info module
# (c) 2021, Hideki Saito <saito@fgrep.org>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Ensure firewalld_info without options
ansible.posix.firewalld_info:
register: result
- name: Assert collected_zones and undefined_zones
ansible.builtin.assert:
that:
- result.collected_zones and not result.undefined_zones
- name: Ensure firewalld_info with active_zones
ansible.posix.firewalld_info:
active_zones: true
register: result
- name: Assert turn active_zones true
ansible.builtin.assert:
that:
- result.collected_zones == ['public']
- name: Ensure firewalld_zones with zone list
ansible.posix.firewalld_info:
zones:
- public
- invalid_zone
register: result
- name: Assert specified zones
ansible.builtin.assert:
that:
- result.collected_zones == ['public']
- result.undefined_zones == ['invalid_zone']
- '"invalid_zone" in result.warnings[0]'
@@ -0,0 +1,41 @@
---
# Test playbook for the firewalld_info module
# (c) 2021, Hideki Saito <saito@fgrep.org>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Ensure firewalld_info without options
ansible.posix.firewalld_info:
register: result
ignore_errors: true
- name: Assert firewalld_info fails if firewalld is not running.
ansible.builtin.assert:
that:
- result.failed
- "'firewalld probably not be running,' in result.msg"
- name: Ensure firewalld_info with active_zones
ansible.posix.firewalld_info:
active_zones: true
register: result
ignore_errors: true
- name: Assert firewalld_info with active_zones fails if firewalld is not running.
ansible.builtin.assert:
that:
- result.failed
- "'firewalld probably not be running,' in result.msg"
- name: Ensure firewalld_zones with zone list
ansible.posix.firewalld_info:
zones:
- public
- invalid_zone
register: result
ignore_errors: true
- name: Assert firewalld_info with zones list fails if firewalld is not running.
ansible.builtin.assert:
that:
- result.failed
- "'firewalld probably not be running,' in result.msg"
@@ -0,0 +1,4 @@
needs/privileged
needs/root
shippable/posix/group1
skip/aix
@@ -0,0 +1,4 @@
destructive
shippable/posix/group1
skip/aix
disabled # fixme package
@@ -0,0 +1,19 @@
Stet clita kasd gubergren,no sea takimata sanctus est Lorem ipsum dolor
sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren,no sea takimata sanctus est Lorem ipsum dolor
sit amet.
@@ -0,0 +1,24 @@
--- origin.txt 2018-05-12 10:22:14.155109584 +0200
+++ result.txt 2018-05-12 10:18:07.230811204 +0200
@@ -2,18 +2,12 @@
sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
-tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
-vero eos et accusam et justo duo dolores et ea rebum.
-
-Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
-sit amet.
-
-Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
-tempor invidunt ut labore et dolore magna aliquyam erat.
+tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
+At vero eos et accusam et justo duo dolores et ea rebum.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum.
-Stet clita kasd gubergren,no sea takimata sanctus est Lorem ipsum dolor
+Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
sit amet.
@@ -0,0 +1,13 @@
Stet clita kasd gubergren,no sea takimata sanctus est Lorem ipsum dolor
sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
At vero eos et accusam et justo duo dolores et ea rebum.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
sit amet.
@@ -0,0 +1,24 @@
--- origin.txt 2018-05-12 10:22:14.155109584 +0200
+++ result.txt 2018-05-12 10:18:07.230811204 +0200
@@ -2,18 +2,12 @@
sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
-tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
-vero eos et accusam et justo duo dolores et ea rebum.
-
-Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
-sit amet.
-
-Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
-tempor invidunt ut labore et dolore magna aliquyam erat.
+tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
+At vero eos et accusam et justo duo dolores et ea rebum.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum.
-Stet clita kasd gubergren,no sea takimata sanctus est Lorem ipsum dolor
+Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor
sit amet.
@@ -0,0 +1,3 @@
---
dependencies:
- prepare_tests
@@ -0,0 +1,147 @@
---
- name: Ensure idempotency installed
ansible.builtin.package:
name: patch
when: ansible_distribution != "MacOSX"
- name: Create a directory for the result
ansible.builtin.file:
dest: "{{ output_dir }}/patch"
state: directory
mode: "0755"
register: result
- name: Assert the directory was created
ansible.builtin.assert:
that:
- result.state == 'directory'
- name: Copy the origin file
ansible.builtin.copy:
src: ./origin.txt
dest: "{{ output_dir }}/patch/workfile.txt"
mode: "0644"
register: result
- name: Patch the origin file in check mode
check_mode: true
register: result
ansible.posix.patch:
src: result.patch
dest: "{{ output_dir }}/patch/workfile.txt"
- name: Verify patch the origin file in check mode
ansible.builtin.assert:
that:
- result is changed
- name: Patch the origin file
register: result
ansible.posix.patch:
src: result.patch
dest: "{{ output_dir }}/patch/workfile.txt"
- name: Verify patch the origin file
ansible.builtin.assert:
that:
- result is changed
- name: Test patch the origin file idempotency
register: result
ansible.posix.patch:
src: result.patch
dest: "{{ output_dir }}/patch/workfile.txt"
- name: Verify test patch the origin file idempotency
ansible.builtin.assert:
that:
- result is not changed
- name: Verify the resulted file matches expectations
ansible.builtin.copy:
src: ./result.txt
dest: "{{ output_dir }}/patch/workfile.txt"
mode: "0644"
register: result
failed_when: result is changed
- name: Patch the workfile file in check mode state absent
check_mode: true
register: result
ansible.posix.patch:
src: result.patch
dest: "{{ output_dir }}/patch/workfile.txt"
state: absent
- name: Verify patch the workfile file in check mode state absent
ansible.builtin.assert:
that:
- result is changed
- name: Patch the workfile file state absent
register: result
ansible.posix.patch:
src: result.patch
dest: "{{ output_dir }}/patch/workfile.txt"
state: absent
- name: Verify patch the workfile file state absent
ansible.builtin.assert:
that:
- result is changed
- name: Patch the workfile file state absent idempotency
register: result
ansible.posix.patch:
src: result.patch
dest: "{{ output_dir }}/patch/workfile.txt"
state: absent
- name: Verify patch the workfile file state absent idempotency
ansible.builtin.assert:
that:
- result is not changed
- name: Verify the resulted file matches expectations
ansible.builtin.copy:
src: ./origin.txt
dest: "{{ output_dir }}/patch/workfile.txt"
mode: "0644"
register: result
failed_when: result is changed
- name: Copy the origin file whitespace
ansible.builtin.copy:
src: ./origin.txt
dest: "{{ output_dir }}/patch/workfile_whitespace.txt"
mode: "0644"
register: result
- name: Patch the origin file
register: result
ansible.posix.patch:
src: result_whitespace.patch
dest: "{{ output_dir }}/patch/workfile_whitespace.txt"
ignore_whitespace: true
- name: Verify patch the origin file
ansible.builtin.assert:
that:
- result is changed
- name: Test patch the origin file idempotency
register: result
ansible.posix.patch:
src: result_whitespace.patch
dest: "{{ output_dir }}/patch/workfile_whitespace.txt"
ignore_whitespace: true
- name: Verify test patch the origin file idempotency
ansible.builtin.assert:
that:
- result is not changed
- name: Verify the resulted file matches expectations
ansible.builtin.copy:
src: ./result_whitespace.txt
dest: "{{ output_dir }}/patch/workfile_whitespace.txt"
mode: "0644"
register: result
failed_when: result is changed
@@ -0,0 +1,3 @@
needs/root
shippable/posix/group1
skip/aix
@@ -0,0 +1,23 @@
---
# (c) 2017, Martin Krizek <mkrizek@redhat.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Include_tasks for when SELinux is enabled
ansible.builtin.include_tasks: seboolean.yml
when:
- ansible_selinux is defined
- ansible_selinux.status == 'enabled'
@@ -0,0 +1,107 @@
---
# (c) 2017, Martin Krizek <mkrizek@redhat.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Install requirements for RHEL 7 and earlier
ansible.builtin.package:
name: policycoreutils-python
when:
- ansible_distribution == 'RedHat' and ansible_distribution_major_version is version('7', '<=')
- name: Install requirements for RHEL 8 and later
ansible.builtin.package:
name: policycoreutils-python-utils
when:
- ansible_distribution == 'RedHat' and ansible_distribution_major_version is version('8', '>=')
- name: Get getsebool output preflight
ansible.builtin.shell:
cmd: set -o pipefail && semanage boolean -l | grep 'httpd_can_network_connect\W'
executable: /bin/bash
changed_when: false
register: getsebool_output_preflight
- name: Cleanup
ansible.builtin.shell:
cmd: set -o pipefail && setsebool -P httpd_can_network_connect 0
executable: /bin/bash
changed_when: getsebool_output_preflight.stdout.startswith('httpd_can_network_connect --> on')
- name: Set flag and don't keep it persistent
ansible.posix.seboolean:
name: httpd_can_network_connect
state: true
register: output
- name: Get getsebool output
ansible.builtin.shell:
cmd: set -o pipefail && semanage boolean -l | grep 'httpd_can_network_connect\W'
executable: /bin/bash
changed_when: false
register: getsebool_output
- name: Check output
ansible.builtin.assert:
that:
- output is changed
- output is not failed
- output.name == 'httpd_can_network_connect'
- getsebool_output.stdout.startswith('httpd_can_network_connect (on , off)')
##########################################################################################
- name: Unset flag
ansible.posix.seboolean:
name: httpd_can_network_connect
state: false
- name: Get getsebool output
ansible.builtin.shell:
cmd: set -o pipefail && semanage boolean -l | grep 'httpd_can_network_connect\W'
executable: /bin/bash
changed_when: false
register: getsebool_output
- name: Check output
ansible.builtin.assert:
that:
- output is changed
- output is not failed
- output.name == 'httpd_can_network_connect'
- getsebool_output.stdout.startswith('httpd_can_network_connect (off , off)')
##########################################################################################
- name: Set flag and keep it persistent
ansible.posix.seboolean:
name: httpd_can_network_connect
state: true
persistent: true
register: output
- name: Get getsebool output
ansible.builtin.shell:
cmd: set -o pipefail && semanage boolean -l | grep 'httpd_can_network_connect\W'
executable: /bin/bash
changed_when: false
register: getsebool_output
- name: Check output
ansible.builtin.assert:
that:
- output is changed
- output is not failed
- output.name == 'httpd_can_network_connect'
- getsebool_output.stdout.startswith('httpd_can_network_connect (on , on)')
##########################################################################################
@@ -0,0 +1,3 @@
needs/root
shippable/posix/group1
skip/aix
@@ -0,0 +1,39 @@
---
# (c) 2017, Sam Doran <sdoran@redhat.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: Debug message for when SELinux is disabled
ansible.builtin.debug:
msg: SELinux is disabled
when: ansible_selinux is defined and ansible_selinux.status == 'disabled'
- name: Debug message for when SELinux is enabled and not disabled
ansible.builtin.debug:
msg: SELinux is {{ ansible_selinux.status }}
when: ansible_selinux is defined
- name: Include_tasks for when SELinux is enabled
ansible.builtin.include_tasks: selinux.yml
when:
- ansible_selinux is defined
- ansible_selinux.status == 'enabled'
- name: Include tasks for selogin when SELinux is enabled
ansible.builtin.include_tasks: selogin.yml
when:
- ansible_selinux is defined
- ansible_selinux.status == 'enabled'
@@ -0,0 +1,543 @@
---
# (c) 2017, Sam Doran <sdoran@redhat.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# First Test
# ##############################################################################
# Test changing the state, which requires a reboot
- name: TEST 1 | Make sure grubby is present
ansible.builtin.package:
name: grubby
state: present
- name: TEST 1 | Get current SELinux config file contents
ansible.builtin.slurp:
src: /etc/sysconfig/selinux
register: selinux_config_original_base64
- name: TEST 1 | Register SELinux config and SELinux status
ansible.builtin.set_fact:
selinux_config_original_raw: "{{ selinux_config_original_base64.content | b64decode }}"
before_test_sestatus: "{{ ansible_selinux }}"
- name: TEST 1 | Split by line and register original config
ansible.builtin.set_fact:
selinux_config_original: "{{ selinux_config_original_raw.split('\n') }}"
- name: TEST 1 | Debug selinux_config_original, before_test_sestatus, and ansible_selinux
ansible.builtin.debug:
var: "{{ item }}"
verbosity: 1
loop:
- selinux_config_original
- before_test_sestatus
- ansible_selinux
- name: TEST 1 | Setup SELinux configuration for tests
ansible.posix.selinux:
state: enforcing
policy: targeted
- name: TEST 1 | Disable SELinux
ansible.posix.selinux:
state: disabled
policy: targeted
register: _disable_test1
- name: TEST 1 | Debug _disable_test1
ansible.builtin.debug:
var: _disable_test1
verbosity: 1
- name: Before gathering the fact
ansible.builtin.debug:
msg: "{{ ansible_selinux }}"
- name: TEST 1 | Re-gather facts
ansible.builtin.setup:
- name: After gathering the fact
ansible.builtin.debug:
msg: "{{ ansible_selinux }}"
- name: TEST 1 | Assert that status was changed, reboot_required is True, a warning was displayed, and SELinux is configured properly
ansible.builtin.assert:
that:
- _disable_test1 is changed
- _disable_test1.reboot_required
- (_disable_test1.warnings | length ) >= 1
- ansible_selinux.config_mode == 'disabled'
- ansible_selinux.type == 'targeted'
- name: TEST 1 | Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
verbosity: 1
- name: TEST 1 | Disable SELinux again
ansible.posix.selinux:
state: disabled
policy: targeted
register: _disable_test2
- name: Test 1 | Debug _disable_test2
ansible.builtin.debug:
var: _disable_test2
verbosity: 1
- name: TEST 1 | Assert that no change is reported, a warning was displayed, and reboot_required is True
ansible.builtin.assert:
that:
- _disable_test2 is not changed
- (_disable_test1.warnings | length ) >= 1
- _disable_test2.reboot_required
- name: TEST 1 | Get modified config file
ansible.builtin.slurp:
src: /etc/sysconfig/selinux
register: selinux_config_after_base64
- name: TEST 1 | Register modified config
ansible.builtin.set_fact:
selinux_config_after_raw: "{{ selinux_config_after_base64.content | b64decode }}"
- name: TEST 1 | Split by line and register modified config
ansible.builtin.set_fact:
selinux_config_after: "{{ selinux_config_after_raw.split('\n') }}"
- name: TEST 1 | Debug selinux_config_after
ansible.builtin.debug:
var: selinux_config_after
verbosity: 1
- name: TEST 1 | Ensure SELinux config file is properly formatted
ansible.builtin.assert:
that:
- selinux_config_original | length == selinux_config_after | length
- (selinux_config_after | select("search", "^SELINUX=disabled\s*$") | list | length) > 0
- (selinux_config_after | select("search", "^SELINUXTYPE=targeted\s*$") | list | length) > 0
- name: TEST 1 | Disable SELinux again, with kernel arguments update
ansible.posix.selinux:
state: disabled
policy: targeted
update_kernel_param: true
register: _disable_test2
- name: Check kernel command-line arguments
ansible.builtin.command: grubby --info=DEFAULT
changed_when: false
register: _grubby_test1
- name: TEST 1 | Assert that kernel cmdline contains selinux=0
ansible.builtin.assert:
that:
- "' selinux=0' in _grubby_test1.stdout"
- name: TEST 1 | Enable SELinux, without kernel arguments update
ansible.posix.selinux:
state: disabled
policy: targeted
register: _disable_test2
- name: Check kernel command-line arguments
ansible.builtin.command: grubby --info=DEFAULT
changed_when: false
register: _grubby_test1
- name: TEST 1 | Assert that kernel cmdline still contains selinux=0
ansible.builtin.assert:
that:
- "' selinux=0' in _grubby_test1.stdout"
- name: TEST 1 | Reset SELinux configuration for next test (also kernel args)
ansible.posix.selinux:
state: enforcing
update_kernel_param: true
policy: targeted
- name: Check kernel command-line arguments
ansible.builtin.command: grubby --info=DEFAULT
changed_when: false
register: _grubby_test2
- name: TEST 1 | Assert that kernel cmdline doesn't contain selinux=0
ansible.builtin.assert:
that:
- "' selinux=0' not in _grubby_test2.stdout"
# Second Test
# ##############################################################################
# Test changing only the policy, which does not require a reboot
- name: TEST 2 | Make sure the policy is present
ansible.builtin.package:
name: selinux-policy-mls
state: present
- name: TEST 2 | Set SELinux policy
ansible.posix.selinux:
state: enforcing
policy: mls
register: _state_test1
- name: TEST 2 | Debug _state_test1
ansible.builtin.debug:
var: _state_test1
verbosity: 1
- name: TEST 2 | Re-gather facts
ansible.builtin.setup:
- name: TEST 2 | Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
tags: debug
- name: TEST 2 | Assert that status was changed, reboot_required is False, no warnings were displayed, and SELinux is configured properly
ansible.builtin.assert:
that:
- _state_test1 is changed
- not _state_test1.reboot_required
- _state_test1.warnings is not defined
- ansible_selinux.config_mode == 'enforcing'
- ansible_selinux.type == 'mls'
- name: TEST 2 | Set SELinux policy again
ansible.posix.selinux:
state: enforcing
policy: mls
register: _state_test2
- name: TEST 2 | Debug _state_test2
ansible.builtin.debug:
var: _state_test2
verbosity: 1
- name: TEST 2 | Assert that no change was reported, no warnings were displayed, and reboot_required is False
ansible.builtin.assert:
that:
- _state_test2 is not changed
- _state_test2.warnings is not defined
- not _state_test2.reboot_required
- name: TEST 2 | Get modified config file
ansible.builtin.slurp:
src: /etc/sysconfig/selinux
register: selinux_config_after_base64
- name: TEST 2 | Register modified config
ansible.builtin.set_fact:
selinux_config_after_raw: "{{ selinux_config_after_base64.content | b64decode }}"
- name: TEST 2 | Split by line and register modified config
ansible.builtin.set_fact:
selinux_config_after: "{{ selinux_config_after_raw.split('\n') }}"
- name: TEST 2 | Debug selinux_config_after
ansible.builtin.debug:
var: selinux_config_after
verbosity: 1
- name: TEST 2 | Ensure SELinux config file is properly formatted
ansible.builtin.assert:
that:
- selinux_config_original | length == selinux_config_after | length
- selinux_config_after[selinux_config_after.index('SELINUX=enforcing')] is search("^SELINUX=\w+$")
- selinux_config_after[selinux_config_after.index('SELINUXTYPE=mls')] is search("^SELINUXTYPE=\w+$")
- name: TEST 2 | Reset SELinux configuration for next test
ansible.posix.selinux:
state: enforcing
policy: targeted
# Third Test
# ##############################################################################
# Test changing non-existing policy
- name: TEST 3 | Set SELinux policy
ansible.posix.selinux:
state: enforcing
policy: non-existing-selinux-policy
register: _state_test1
ignore_errors: true
- name: TEST 3 | Debug _state_test1
ansible.builtin.debug:
var: _state_test1
verbosity: 1
- name: TEST 3 | Re-gather facts
ansible.builtin.setup:
- name: TEST3 | Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
tags: debug
- name: TEST 3 | Assert that status was not changed, the task failed, the msg contains proper information and SELinux was not changed
ansible.builtin.assert:
that:
- _state_test1 is not changed
- _state_test1 is failed
- _state_test1.msg == 'Policy non-existing-selinux-policy does not exist in /etc/selinux/'
- ansible_selinux.config_mode == 'enforcing'
- ansible_selinux.type == 'targeted'
# Fourth Test
# ##############################################################################
# Test if check mode returns correct changed values and
# doesn't make any changes
- name: TEST 4 | Set SELinux to enforcing
ansible.posix.selinux:
state: enforcing
policy: targeted
register: _check_mode_test1
- name: TEST 4 | Debug _check_mode_test1
ansible.builtin.debug:
var: _check_mode_test1
verbosity: 1
- name: TEST 4 | Set SELinux to enforcing in check mode
ansible.posix.selinux:
state: enforcing
policy: targeted
register: _check_mode_test1
check_mode: true
- name: TEST 4 | Re-gather facts
ansible.builtin.setup:
- name: TEST 4| Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
verbosity: 1
tags: debug
- name: TEST 4 | Assert that check mode is idempotent
ansible.builtin.assert:
that:
- _check_mode_test1 is success
- not _check_mode_test1.reboot_required
- ansible_selinux.config_mode == 'enforcing'
- ansible_selinux.type == 'targeted'
- name: TEST 4 | Set SELinux to permissive in check mode
ansible.posix.selinux:
state: permissive
policy: targeted
register: _check_mode_test2
check_mode: true
- name: TEST 4 | Re-gather facts
ansible.builtin.setup:
- name: TEST 4 | Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
verbosity: 1
tags: debug
- name: TEST 4 | Assert that check mode doesn't set state permissive and returns changed
ansible.builtin.assert:
that:
- _check_mode_test2 is changed
- not _check_mode_test2.reboot_required
- ansible_selinux.config_mode == 'enforcing'
- ansible_selinux.type == 'targeted'
- name: TEST 4 | Disable SELinux in check mode
ansible.posix.selinux:
state: disabled
register: _check_mode_test3
check_mode: true
- name: TEST 4 | Re-gather facts
ansible.builtin.setup:
- name: TEST 4 | Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
verbosity: 1
tags: debug
- name: TEST 4 | Assert that check mode didn't change anything, status is changed, reboot_required is True, a warning was displayed
ansible.builtin.assert:
that:
- _check_mode_test3 is changed
- _check_mode_test3.reboot_required
- (_check_mode_test3.warnings | length ) >= 1
- ansible_selinux.config_mode == 'enforcing'
- ansible_selinux.type == 'targeted'
- name: TEST 4 | Set SELinux to permissive
ansible.posix.selinux:
state: permissive
policy: targeted
register: _check_mode_test4
- name: TEST 4 | Debug _check_mode_test4
ansible.builtin.debug:
var: _check_mode_test4
verbosity: 1
- name: TEST 4 | Disable SELinux in check mode
ansible.posix.selinux:
state: disabled
register: _check_mode_test4
check_mode: true
- name: TEST 4 | Re-gather facts
ansible.builtin.setup:
- name: TEST 4 | Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
verbosity: 1
tags: debug
- name: TEST 4 | Assert that check mode didn't change anything, status is changed, reboot_required is True, a warning was displayed
ansible.builtin.assert:
that:
- _check_mode_test4 is changed
- _check_mode_test4.reboot_required
- (_check_mode_test3.warnings | length ) >= 1
- ansible_selinux.config_mode == 'permissive'
- ansible_selinux.type == 'targeted'
- name: TEST 4 | Set SELinux to enforcing
ansible.posix.selinux:
state: enforcing
policy: targeted
register: _check_mode_test5
- name: TEST 4 | Debug _check_mode_test5
ansible.builtin.debug:
var: _check_mode_test5
verbosity: 1
- name: TEST 4 | Disable SELinux
ansible.posix.selinux:
state: disabled
register: _check_mode_test5
- name: TEST 4 | Disable SELinux in check mode
ansible.posix.selinux:
state: disabled
register: _check_mode_test5
check_mode: true
- name: TEST 4 | Re-gather facts
ansible.builtin.setup:
- name: TEST 4 | Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
verbosity: 1
tags: debug
- name: TEST 4 | Assert that in check mode status was not changed, reboot_required is True, a warning was displayed, and SELinux is configured properly
ansible.builtin.assert:
that:
- _check_mode_test5 is success
- _check_mode_test5.reboot_required
- (_check_mode_test5.warnings | length ) >= 1
- ansible_selinux.config_mode == 'disabled'
- ansible_selinux.type == 'targeted'
# Fifth Test
# ##############################################################################
# Remove SELINUX and SELINUXTYPE keys from /etc/selinux/config and make
# sure the module re-adds the expected lines
- name: TEST 5 | Remove SELINUX key from /etc/selinux/config
ansible.builtin.lineinfile:
path: /etc/selinux/config
regexp: ^SELINUX=
state: absent
backup: true
register: _lineinfile_out1
- name: TEST 5 | Debug _lineinfile_out1
ansible.builtin.debug:
var: _lineinfile_out1
verbosity: 1
- name: TEST 5 | Set SELinux to enforcing
ansible.posix.selinux:
state: enforcing
policy: targeted
register: _set_enforcing1
- name: TEST 5 | Re-gather facts
ansible.builtin.setup:
- name: TEST 5 | Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
verbosity: 1
- name: TEST 5 | Assert that SELINUX key is populated
ansible.builtin.assert:
that:
- _set_enforcing1 is success
- _set_enforcing1 is changed
- _set_enforcing1.state == 'enforcing'
- ansible_selinux.config_mode == 'enforcing'
- name: TEST 5 | Remove SELINUXTYPE key from /etc/selinux/config
ansible.builtin.lineinfile:
path: /etc/selinux/config
regexp: ^SELINUXTYPE=
state: absent
register: _lineinfile_out2
- name: TEST 5 | Debug _lineinfile_out2
ansible.builtin.debug:
var: _lineinfile_out2
verbosity: 1
- name: TEST 5 | Set SELinux Policy to targeted
ansible.posix.selinux:
state: enforcing
policy: targeted
register: _set_policy2
- name: TEST 5 | Re-gather facts
ansible.builtin.setup:
- name: TEST 5 | Debug ansible_selinux
ansible.builtin.debug:
var: ansible_selinux
verbosity: 1
- name: TEST 5 | Assert that SELINUXTYPE key is populated
ansible.builtin.assert:
that:
- _set_policy2 is success
- _set_policy2 is changed
- _set_policy2.policy == 'targeted'
- ansible_selinux.type == 'targeted'
- name: TEST 5 | Restore original SELinux config file /etc/selinux/config
ansible.builtin.copy:
dest: /etc/selinux/config
src: "{{ _lineinfile_out1['backup'] }}"
remote_src: true
mode: "0644"
@@ -0,0 +1,71 @@
---
- name: Create user for testing
ansible.builtin.user:
name: seuser
- name: Attempt to add mapping without 'seuser'
register: selogin_error
ignore_errors: true
community.general.selogin:
login: seuser
- name: Verify failure
ansible.builtin.assert:
that:
- selogin_error is failed
- name: Map login to SELinux user
register: selogin_new_mapping
check_mode: "{{ item }}"
with_items:
- true
- false
- true
- false
community.general.selogin:
login: seuser
seuser: staff_u
- name: New mapping- verify functionality and check_mode
ansible.builtin.assert:
that:
- selogin_new_mapping.results[0] is changed
- selogin_new_mapping.results[1] is changed
- selogin_new_mapping.results[2] is not changed
- selogin_new_mapping.results[3] is not changed
- name: Change SELinux user login mapping
register: selogin_mod_mapping
check_mode: "{{ item }}"
with_items:
- true
- false
- true
- false
community.general.selogin:
login: seuser
seuser: user_u
- name: Changed mapping- verify functionality and check_mode
ansible.builtin.assert:
that:
- selogin_mod_mapping.results[0] is changed
- selogin_mod_mapping.results[1] is changed
- selogin_mod_mapping.results[2] is not changed
- selogin_mod_mapping.results[3] is not changed
- name: Remove SELinux user mapping
register: selogin_del_mapping
check_mode: "{{ item }}"
with_items:
- true
- false
- true
- false
community.general.selogin:
login: seuser
state: absent
- name: Delete mapping- verify functionality and check_mode
ansible.builtin.assert:
that:
- selogin_del_mapping.results[0] is changed
- selogin_del_mapping.results[1] is changed
- selogin_del_mapping.results[2] is not changed
- selogin_del_mapping.results[3] is not changed
- name: Remove test user
ansible.builtin.user:
name: seuser
state: absent
@@ -0,0 +1,19 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
- name: Set pkg_mgr and ansible_pkg_mgr on FreeBSD
ansible.builtin.set_fact:
pkg_mgr: community.general.pkgng
ansible_pkg_mgr: community.general.pkgng
cacheable: true
when: ansible_os_family == "FreeBSD"
- name: Set pkg_mgr and ansible_pkg_mgr on Suse
ansible.builtin.set_fact:
pkg_mgr: community.general.zypper
ansible_pkg_mgr: community.general.zypper
cacheable: true
when: ansible_os_family == "Suse"
@@ -0,0 +1,3 @@
---
dependencies:
- prepare_tests
@@ -0,0 +1,350 @@
---
- name: Install rsync
ansible.builtin.package:
name: rsync
when: ansible_distribution != "MacOSX"
- name: Clean up the working disrectory and files
ansible.builtin.file:
path: "{{ output_dir }}"
state: absent
- name: Create the working directory
ansible.builtin.file:
path: "{{ output_dir }}"
state: directory
mode: "0755"
- name: Create test new files
ansible.builtin.copy:
dest: "{{ output_dir }}/{{ item }}"
mode: "0644"
content: hello world
loop:
- foo.txt
- bar.txt
- name: Synchronize file to new filename
ansible.posix.synchronize:
src: "{{ output_dir }}/foo.txt"
dest: "{{ output_dir }}/foo.result"
register: sync_result
delegate_to: "{{ inventory_hostname }}"
- name: Check that the file was copied over correctly
ansible.builtin.assert:
that:
- "'changed' in sync_result"
- sync_result.changed == true
- "'cmd' in sync_result"
- "'rsync' in sync_result.cmd"
- "'msg' in sync_result"
- sync_result.msg.startswith('>f+')
- "sync_result.msg.endswith('+ foo.txt\n')"
- name: Test that the file was really copied over
ansible.builtin.stat:
path: "{{ output_dir }}/foo.result"
register: stat_result
- name: Test that the file was really copied over
ansible.builtin.assert:
that:
- stat_result.stat.exists == True
- stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
- name: Test that the file is not copied a second time
ansible.posix.synchronize:
src: "'{{ output_dir }}/foo.txt'"
dest: "'{{ output_dir }}/foo.result'"
register: sync_result
delegate_to: "{{ inventory_hostname }}"
- name: Test that no change occurred
ansible.builtin.assert:
that:
- not sync_result.changed
- name: Cleanup
ansible.builtin.file:
state: absent
path: "{{ output_dir }}/{{ item }}"
loop:
- foo.result
- bar.result
- name: Synchronize using the mode=push param
ansible.posix.synchronize:
src: "{{ output_dir }}/foo.txt"
dest: "{{ output_dir }}/foo.result"
mode: push
register: sync_result
delegate_to: "{{ inventory_hostname }}"
- name: Check that the file was copied over correctly mode=push
ansible.builtin.assert:
that:
- "'changed' in sync_result"
- sync_result.changed == true
- "'cmd' in sync_result"
- "'rsync' in sync_result.cmd"
- "'msg' in sync_result"
- sync_result.msg.startswith('>f+')
- "sync_result.msg.endswith('+ foo.txt\n')"
- name: Test that the file was really copied over
ansible.builtin.stat:
path: "{{ output_dir }}/foo.result"
register: stat_result
- name: Ensure file exists and checksum matches
ansible.builtin.assert:
that:
- stat_result.stat.exists == True
- stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
- name: Test that the file is not copied a second time
ansible.posix.synchronize:
src: "{{ output_dir }}/foo.txt"
dest: "{{ output_dir }}/foo.result"
mode: push
register: sync_result
delegate_to: "{{ inventory_hostname }}"
- name: Ensure no change occorred
ansible.builtin.assert:
that:
- sync_result.changed == False
- name: Cleanup
ansible.builtin.file:
state: absent
path: "{{ output_dir }}/{{ item }}"
loop:
- foo.result
- bar.result
- name: Synchronize using the mode=pull param
ansible.posix.synchronize:
src: "{{ output_dir }}/foo.txt"
dest: "{{ output_dir }}/foo.result"
mode: pull
register: sync_result
delegate_to: "{{ inventory_hostname }}"
- name: Check that the file was copied over correctly mode=pull
ansible.builtin.assert:
that:
- "'changed' in sync_result"
- sync_result.changed == true
- "'cmd' in sync_result"
- "'rsync' in sync_result.cmd"
- "'msg' in sync_result"
- sync_result.msg.startswith('>f+')
- "sync_result.msg.endswith('+ foo.txt\n')"
- name: Test that the file was really copied over
ansible.builtin.stat:
path: "{{ output_dir }}/foo.result"
register: stat_result
- name: Ensure file exists and checksum matches
ansible.builtin.assert:
that:
- stat_result.stat.exists == True
- stat_result.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
- name: Test that the file is not copied a second time
ansible.posix.synchronize:
src: "{{ output_dir }}/foo.txt"
dest: "{{ output_dir }}/foo.result"
mode: pull
register: sync_result
delegate_to: "{{ inventory_hostname }}"
- name: Ensure no change occorred
ansible.builtin.assert:
that:
- sync_result.changed == False
- name: Cleanup
ansible.builtin.file:
state: absent
path: "{{ output_dir }}/{{ item }}"
loop:
- foo.result
- bar.result
- name: Synchronize files using with_items (issue#5965)
ansible.posix.synchronize:
src: "{{ output_dir }}/{{ item }}"
dest: "{{ output_dir }}/{{ item }}.result"
with_items:
- foo.txt
- bar.txt
register: sync_result
delegate_to: "{{ inventory_hostname }}"
- name: Validate syncrhonize with_items
ansible.builtin.assert:
that:
- sync_result.changed
- sync_result.msg == 'All items completed'
- "'results' in sync_result"
- sync_result.results|length == 2
- "sync_result.results[0].msg.endswith('+ foo.txt\n')"
- "sync_result.results[1].msg.endswith('+ bar.txt\n')"
- name: Cleanup
ansible.builtin.file:
state: absent
path: "{{ output_dir }}/{{ item }}.result"
loop:
- foo.txt
- bar.txt
- name: Synchronize files using rsync_path (issue#7182)
ansible.posix.synchronize:
src: "{{ output_dir }}/foo.txt"
dest: "{{ output_dir }}/foo.rsync_path"
rsync_path: sudo rsync
register: sync_result
delegate_to: "{{ inventory_hostname }}"
- name: Validate syncrhonize using rsync_path (issue#7182)
ansible.builtin.assert:
that:
- "'changed' in sync_result"
- sync_result.changed == true
- "'cmd' in sync_result"
- "'rsync' in sync_result.cmd"
- "'rsync_path' in sync_result.cmd"
- "'msg' in sync_result"
- sync_result.msg.startswith('>f+')
- "sync_result.msg.endswith('+ foo.txt\n')"
- name: Cleanup
ansible.builtin.file:
state: absent
path: "{{ output_dir }}/{{ item }}"
loop:
- foo.rsync_path
- name: Add subdirectories for link-dest test
ansible.builtin.file:
path: "{{ output_dir }}/{{ item }}/"
state: directory
mode: "0755"
loop:
- directory_a
- directory_b
- name: Copy foo.txt into the first directory
ansible.posix.synchronize:
src: "{{ output_dir }}/foo.txt"
dest: "{{ output_dir }}/{{ item }}/foo.txt"
loop:
- directory_a
delegate_to: "{{ inventory_hostname }}"
- name: Synchronize files using link_dest
ansible.posix.synchronize:
src: "{{ output_dir }}/directory_a/foo.txt"
dest: "{{ output_dir }}/directory_b/foo.txt"
link_dest:
- "{{ output_dir }}/directory_a"
register: sync_result
delegate_to: "{{ inventory_hostname }}"
- name: Get stat information for directory_a
ansible.builtin.stat:
path: "{{ output_dir }}/directory_a/foo.txt"
register: stat_result_a
- name: Get stat information for directory_b
ansible.builtin.stat:
path: "{{ output_dir }}/directory_b/foo.txt"
register: stat_result_b
- name: Ensure file exists and inode matches
ansible.builtin.assert:
that:
- "'changed' in sync_result"
- sync_result.changed == true
- stat_result_a.stat.inode == stat_result_b.stat.inode
- name: Synchronize files using link_dest that would be recursive
ansible.posix.synchronize:
src: "{{ output_dir }}/foo.txt"
dest: "{{ output_dir }}/foo.result"
link_dest:
- "{{ output_dir }}"
register: sync_result
ignore_errors: true
delegate_to: "{{ inventory_hostname }}"
- name: Ensure no change occorred and failed
ansible.builtin.assert:
that:
- sync_result is not changed
- sync_result is failed
- name: Cleanup
ansible.builtin.file:
state: absent
path: "{{ output_dir }}/{{ item }}"
loop:
- directory_b/foo.txt
- directory_a/foo.txt
- directory_a
- directory_b
- name: Setup - test for source with working dir with spaces in path
ansible.builtin.file:
state: directory
path: "{{ output_dir }}/{{ item }}"
mode: "0755"
delegate_to: "{{ inventory_hostname }}"
loop:
- directory a
- directory b
- name: Setup - create test new files
ansible.builtin.copy:
dest: "{{ output_dir }}/directory a/{{ item }}"
mode: "0644"
content: hello world
loop:
- foo.txt
delegate_to: "{{ inventory_hostname }}"
- name: Copy source with spaces in dir path
ansible.posix.synchronize:
src: "{{ output_dir }}/directory a/foo.txt"
dest: "{{ output_dir }}/directory b/"
delegate_to: "{{ inventory_hostname }}"
register: sync_result
ignore_errors: true
- name: Get stat information for directory_b
ansible.builtin.stat:
path: "{{ output_dir }}/directory b/foo.txt"
register: stat_result_b
- name: Ensure file exists and checksum matches
ansible.builtin.assert:
that:
- "'changed' in sync_result"
- sync_result.changed == true
- stat_result_b.stat.exists == True
- stat_result_b.stat.checksum == '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
- name: Cleanup
ansible.builtin.file:
state: absent
path: "{{ output_dir }}/{{ item }}"
loop:
- directory b/foo.txt
- directory a/foo.txt
- directory a
- directory b
@@ -0,0 +1,4 @@
shippable/posix/group1
skip/aix
skip/freebsd
skip/osx
@@ -0,0 +1,12 @@
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.swappiness=1
kernel.panic=2
@@ -0,0 +1,3 @@
---
dependencies:
- prepare_tests
@@ -0,0 +1,368 @@
---
# Test code for the sysctl module.
# (c) 2017, James Tanner <tanner.jc@gmail.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# NOTE: Testing sysctl inside an unprivileged container means that we cannot
# apply sysctl, or it will always fail, because of that in most cases (except
# those when it should fail) we have to use `reload=no`.
- name: Test inside Docker
when:
- ansible_facts.virtualization_type == 'docker' or ansible_facts.virtualization_type == 'container'
block:
- name: Set output_dir_test fact
ansible.builtin.set_fact:
output_dir_test: "{{ output_dir }}/test_sysctl"
- name: Make sure our testing sub-directory does not exist
ansible.builtin.file:
path: "{{ output_dir_test }}"
state: absent
- name: Create our testing sub-directory
ansible.builtin.file:
path: "{{ output_dir_test }}"
state: directory
mode: "0755"
##
## sysctl - file manipulation
##
- name: Copy the example conf to the test dir
ansible.builtin.copy:
src: sysctl.conf
dest: "{{ output_dir_test }}"
mode: "0644"
- name: Set vm.swappiness to 5
ansible.posix.sysctl:
name: vm.swappiness
value: 5
state: present
reload: false
sysctl_file: "{{ output_dir_test }}/sysctl.conf"
register: sysctl_test0
- name: Debug sysctl_test0
ansible.builtin.debug:
var: sysctl_test0
verbosity: 1
- name: Get file content
ansible.builtin.shell:
cmd: set -o pipefail && cat {{ output_dir_test }}/sysctl.conf | egrep -v ^\#
executable: /bin/bash
changed_when: false
register: sysctl_content0
- name: Debug sysctl_content0
ansible.builtin.debug:
var: sysctl_content0
verbosity: 1
- name: Set vm.swappiness to 5 again
ansible.posix.sysctl:
name: vm.swappiness
value: 5
state: present
reload: false
sysctl_file: "{{ output_dir_test }}/sysctl.conf"
register: sysctl_test1
- name: Validate results
ansible.builtin.assert:
that:
- sysctl_test0 is changed
- sysctl_test1 is not changed
- sysctl_content0.stdout_lines[sysctl_content0.stdout_lines.index("vm.swappiness=5")] == "vm.swappiness=5"
- name: Remove kernel.panic
ansible.posix.sysctl:
name: kernel.panic
value: 2
reload: false
state: absent
sysctl_file: "{{ output_dir_test }}/sysctl.conf"
register: sysctl_test2
- name: Get file content
ansible.builtin.shell:
cmd: set -o pipefail && cat {{ output_dir_test }}/sysctl.conf | egrep -v ^\#
executable: /bin/bash
changed_when: false
register: sysctl_content2
- name: Debug sysctl_test2 sysctl_content2
ansible.builtin.debug:
var: item
verbosity: 1
with_items:
- "{{ sysctl_test2 }}"
- "{{ sysctl_content2 }}"
- name: Validate results for key removal
ansible.builtin.assert:
that:
- sysctl_test2 is changed
- "'kernel.panic' not in sysctl_content2.stdout_lines"
- name: Test remove kernel.panic again
ansible.posix.sysctl:
name: kernel.panic
value: 2
state: absent
reload: false
sysctl_file: "{{ output_dir_test }}/sysctl.conf"
register: sysctl_test2_change_test
- name: Assert that no change was made
ansible.builtin.assert:
that:
- sysctl_test2_change_test is not changed
- name: Try sysctl with an invalid name
ansible.posix.sysctl:
name: test.invalid
value: 1
register: sysctl_test3
ignore_errors: true
- name: Debug sysctl_test3
ansible.builtin.debug:
var: sysctl_test3
verbosity: 1
- name: Validate results for test 3
ansible.builtin.assert:
that:
- sysctl_test3 is failed
##
## sysctl - sysctl_set
##
- name: Set net.ipv4.ip_forward
ansible.posix.sysctl:
name: net.ipv4.ip_forward
value: 1
sysctl_set: true
reload: false
register: sysctl_test3
- name: Check with sysctl command
ansible.builtin.command: sysctl net.ipv4.ip_forward
changed_when: false
register: sysctl_check3
- name: Debug sysctl_test3 sysctl_check3
ansible.builtin.debug:
var: item
verbosity: 1
with_items:
- "{{ sysctl_test3 }}"
- "{{ sysctl_check3 }}"
- name: Validate results for test 3
ansible.builtin.assert:
that:
- sysctl_test3 is changed
- sysctl_check3.stdout_lines == ["net.ipv4.ip_forward = 1"]
- name: Try sysctl with no name
ansible.posix.sysctl:
name: ""
value: 1
sysctl_set: true
ignore_errors: true
register: sysctl_no_name
- name: Validate nameless results
ansible.builtin.assert:
that:
- sysctl_no_name is failed
- sysctl_no_name.msg == 'name cannot be blank'
- name: Try sysctl with no value
ansible.posix.sysctl:
name: Foo
value:
sysctl_set: true
ignore_errors: true
register: sysctl_no_value
- name: Validate nameless results
ansible.builtin.assert:
that:
- sysctl_no_value is failed
- sysctl_no_value.msg == 'value cannot be None'
- name: Try sysctl with an invalid name
ansible.posix.sysctl:
name: test.invalid
value: 1
sysctl_set: true
register: sysctl_test4
ignore_errors: true
- name: Debug sysctl_test4
ansible.builtin.debug:
var: sysctl_test4
verbosity: 1
- name: Validate results for test 4
ansible.builtin.assert:
that:
- sysctl_test4 is failed
- name: Test on RHEL VMs
when:
- ansible_facts.virtualization_type != 'docker'
- ansible_facts.distribution == 'RedHat'
block:
# Test reload: yes
- name: Set sysctl property using module
ansible.posix.sysctl:
name: vm.swappiness
value: "22"
state: present
reload: true
register: sysctl_set1
- name: Change sysctl property using command
ansible.builtin.command: sysctl vm.swappiness=33
changed_when: true
- name: Set sysctl property using module
ansible.posix.sysctl:
name: vm.swappiness
value: "22"
state: present
reload: true
register: sysctl_set2
- name: Read /etc/sysctl.conf
ansible.builtin.command: egrep -v ^# /etc/sysctl.conf
changed_when: false
register: sysctl_conf_content
- name: Get current value of vm.swappiness
ansible.builtin.command: sysctl -n vm.swappiness
changed_when: false
register: sysctl_current_vm_swappiness
- name: Ensure changes were made appropriately
ansible.builtin.assert:
that:
- sysctl_set1 is changed
- sysctl_set2 is changed
- "'vm.swappiness=22' in sysctl_conf_content.stdout_lines"
- sysctl_current_vm_swappiness.stdout == '22'
# Test reload: yes in check mode
- name: Set the same value using module in check mode
ansible.posix.sysctl:
name: vm.swappiness
value: "22"
state: present
reload: true
check_mode: true
register: sysctl_check_mode1
- name: Set a different value using module in check mode
ansible.posix.sysctl:
name: vm.swappiness
value: "44"
state: present
reload: true
check_mode: true
register: sysctl_check_mode2
- name: Read /etc/sysctl.conf
ansible.builtin.command: egrep -v ^# /etc/sysctl.conf
changed_when: false
register: sysctl_check_mode_conf_content
- name: Get current value of vm.swappiness
ansible.builtin.command: sysctl -n vm.swappiness
changed_when: false
register: sysctl_check_mode_current_vm_swappiness
- name: Ensure no changes were made in check mode
ansible.builtin.assert:
that:
- sysctl_check_mode1 is success
- sysctl_check_mode2 is changed
- "'vm.swappiness=22' in sysctl_check_mode_conf_content.stdout_lines"
- sysctl_check_mode_current_vm_swappiness.stdout == '22'
# Test sysctl: invalid value
- name: Set invalid sysctl property using module
ansible.posix.sysctl:
name: vm.mmap_rnd_bits
value: "1024"
state: present
reload: true
sysctl_set: true
ignore_errors: true
register: sysctl_invalid_set1
- name: Read /etc/sysctl.conf
ansible.builtin.command: cat /etc/sysctl.conf
changed_when: false
register: sysctl_invalid_conf_content
- name: Ensure changes were not made
ansible.builtin.assert:
that:
- sysctl_invalid_set1 is failed
- "'vm.mmap_rnd_bits' not in sysctl_invalid_conf_content.stdout"
# Test sysctl: sysctl_file is symlink
- name: Create link source
ansible.builtin.copy:
content: |
# Testing Ansible Sysctl module on symlink.
dest: /tmp/ansible_sysctl_test.conf
mode: "0644"
- name: Create symlink to the conf file
ansible.builtin.file:
src: /tmp/ansible_sysctl_test.conf
dest: /tmp/ansible_sysctl_test_symlink.conf
state: link
- name: Use sysctl module with symlink sysctl file
ansible.posix.sysctl:
name: 'kernel.randomize_va_space'
value: '1'
sysctl_file: /tmp/ansible_sysctl_test_symlink.conf
state: present
sysctl_set: false
reload: false
- name: Stat sysctl file
ansible.builtin.stat:
path: /tmp/ansible_sysctl_test_symlink.conf
register: stat_result
- name: Ensure the sysctl file remains a symlink
ansible.builtin.assert:
that:
- stat_result.stat.islnk is defined and stat_result.stat.islnk
- stat_result.stat.lnk_source == '/tmp/ansible_sysctl_test.conf'