Skip to content
Snippets Groups Projects
Commit 6c94fe9b authored by Rafael Guterres Jeffman's avatar Rafael Guterres Jeffman
Browse files

tests/sudorule: Don't become or gather_facts and use only true/false

Unless there's a real need to use privileged access or to gather Ansible
facts upfront, we should always set "become: false" and
"gather_facts: false". In the case that only a few Ansible facts are
required, 'ansible.builtin.setup' with 'gather_subset' should be used.

As the YAML 1.2 standard dictates, boolean values should only use 'true'
or 'false' values.

This patch fixes these issues in the 'sudorule' test suite.
parent 4fa06211
Branches
Tags
No related merge requests found
...@@ -3,11 +3,15 @@ ...@@ -3,11 +3,15 @@
- name: Test sudorule - name: Test sudorule
hosts: "{{ ipa_test_host | default('ipaserver') }}" hosts: "{{ ipa_test_host | default('ipaserver') }}"
become: true become: true
gather_facts: true gather_facts: false
tasks: tasks:
# setup # setup
- name: Ensure DNS Ansible facts are available
ansible.builtin.setup:
gather_subset: dns
- name: Ensure test user is present - name: Ensure test user is present
ipauser: ipauser:
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword
...@@ -1157,7 +1161,7 @@ ...@@ -1157,7 +1161,7 @@
hostmask: 192.168.120.0/24 hostmask: 192.168.120.0/24
action: member action: member
register: result register: result
check_mode: yes check_mode: true
failed_when: not result.changed or result.failed failed_when: not result.changed or result.failed
- name: Ensure sudorule hostmask member is present - name: Ensure sudorule hostmask member is present
......
--- ---
- name: Test sudorule user category - name: Test sudorule user category
hosts: ipaserver hosts: ipaserver
become: yes become: false
gather_facts: yes gather_facts: false
tasks: tasks:
- name: Test sudorule single hostnames
block:
# setup test environment
- name: Ensure ipaserver_domain is set
when: ipaserver_domain is not defined
block:
- name: Retrieve host information
ansible.builtin.setup:
gather_subset: dns
- name: Get Domain from the server name - name: Get Domain from the server name
ansible.builtin.set_fact: ansible.builtin.set_fact:
ipaserver_domain: "{{ ansible_facts['fqdn'].split('.')[1:] | join('.') }}" ipaserver_domain: "{{ ansible_facts['fqdn'].split('.')[1:] | join('.') }}"
......
--- ---
- name: Test sudorule - name: Test sudorule
hosts: ipaclients, ipaserver hosts: ipaclients, ipaserver
become: no become: false
gather_facts: no gather_facts: false
tasks: tasks:
- name: Include FreeIPA facts. - name: Include FreeIPA facts.
......
--- ---
- name: Test sudorule members should be case insensitive. - name: Test sudorule members should be case insensitive.
hosts: "{{ ipa_test_host | default('ipaserver') }}" hosts: "{{ ipa_test_host | default('ipaserver') }}"
become: no become: false
gather_facts: no gather_facts: false
vars: vars:
groups_present: groups_present:
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
ipahost: ipahost:
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword
name: "{{ item }}.{{ ipa_domain }}" name: "{{ item }}.{{ ipa_domain }}"
force: yes force: true
loop: "{{ groups_present }}" loop: "{{ groups_present }}"
- name: Ensure test users exist. - name: Ensure test users exist.
......
--- ---
- name: Test sudorule with single hostnames. - name: Test sudorule with single hostnames.
hosts: "{{ ipa_test_host | default('ipaserver') }}" hosts: "{{ ipa_test_host | default('ipaserver') }}"
become: no become: false
gather_facts: no gather_facts: false
tasks: tasks:
- name: Test sudorule single hostnames - name: Test sudorule single hostnames
block: block:
# setup test environment # setup test environment
- name: Ensure ipaserver_domain is set
when: ipaserver_domain is not defined
block:
- name: Retrieve host information
ansible.builtin.setup:
gather_subset: dns
- name: Get Domain from the server name - name: Get Domain from the server name
ansible.builtin.set_fact: ansible.builtin.set_fact:
ipaserver_domain: "{{ ansible_facts['fqdn'].split('.')[1:] | join('.') }}" ipaserver_domain: "{{ ansible_facts['fqdn'].split('.')[1:] | join('.') }}"
when: ipaserver_domain is not defined
- name: Ensure test sudo rule is absent - name: Ensure test sudo rule is absent
ipasudorule: ipasudorule:
...@@ -24,9 +29,9 @@ ...@@ -24,9 +29,9 @@
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword
hosts: hosts:
- name: "host01.{{ ipaserver_domain }}" - name: "host01.{{ ipaserver_domain }}"
force: yes force: true
- name: "host02.{{ ipaserver_domain }}" - name: "host02.{{ ipaserver_domain }}"
force: yes force: true
# start tests # start tests
- name: Ensure sudorule exist with host member using FQDN. - name: Ensure sudorule exist with host member using FQDN.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- name: Test sudorule - name: Test sudorule
hosts: "{{ ipa_test_host | default('ipaserver') }}" hosts: "{{ ipa_test_host | default('ipaserver') }}"
become: false become: false
gather_facts: true # required for ansible_facts['fqdn'] gather_facts: false
module_defaults: module_defaults:
ipauser: ipauser:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment