Allow multiple services creation

Adding an option to create multiple services in one go.
Adding tests (present/absent/without_skip_host_check)

Copied from PR #1054

Signed-off-by: Denis Karpelevich <dkarpele@redhat.com>
This commit is contained in:
Denis Karpelevich
2023-03-03 22:01:57 +01:00
committed by Thomas Woerner
parent 180afd7586
commit 0d9873b81c
9 changed files with 555 additions and 56 deletions

View File

@@ -0,0 +1,22 @@
---
- name: Create services.json
hosts: localhost
tasks:
- name: Check if services.json exists
ansible.builtin.stat:
path: services.json
register: register_stat_services
- name: Create services.json
ansible.builtin.command: /bin/bash services.sh 500
when: not register_stat_services.stat.exists
- name: Check if hosts.json exists
ansible.builtin.stat:
path: hosts.json
register: register_stat_hosts
- name: Create hosts.json
ansible.builtin.command: /bin/bash hosts.sh 500
when: not register_stat_hosts.stat.exists

24
tests/service/hosts.sh Normal file
View File

@@ -0,0 +1,24 @@
#!/bin/bash -eu
NUM=${1-1000}
FILE="hosts.json"
echo "{" > "$FILE"
echo " \"host_list\": [" >> "$FILE"
for i in $(seq 1 "$NUM"); do
{
echo " {"
echo " \"name\": \"www.example$i.com\""
} >> "$FILE"
if [ "$i" -lt "$NUM" ]; then
echo " }," >> "$FILE"
else
echo " }" >> "$FILE"
fi
done
echo " ]" >> "$FILE"
echo "}" >> "$FILE"

25
tests/service/services.sh Normal file
View File

@@ -0,0 +1,25 @@
#!/bin/bash -eu
NUM=${1-1000}
FILE="services.json"
echo "{" > "$FILE"
echo " \"service_list\": [" >> "$FILE"
for i in $(seq 1 "$NUM"); do
{
echo " {"
echo " \"name\": \"HTTP/www.example$i.com\","
echo " \"principal\": \"host/test.example$i.com\""
} >> "$FILE"
if [ "$i" -lt "$NUM" ]; then
echo " }," >> "$FILE"
else
echo " }" >> "$FILE"
fi
done
echo " ]" >> "$FILE"
echo "}" >> "$FILE"

View File

@@ -0,0 +1,22 @@
#!/bin/bash -eu
NUM=1000
FILE="services_absent.json"
echo "{" > "$FILE"
echo " \"services\": [" >> "$FILE"
for i in $(seq 1 "$NUM"); do
echo " {" >> "$FILE"
echo " \"name\": \"HTTP/www.example$i.com\"," >> "$FILE"
if [ "$i" -lt "$NUM" ]; then
echo " }," >> "$FILE"
else
echo " }" >> "$FILE"
fi
done
echo " ]" >> "$FILE"
echo "}" >> "$FILE"

View File

@@ -0,0 +1,32 @@
---
- name: Include create_services_json.yml
ansible.builtin.import_playbook: create_services_json.yml
- name: Test services absent
hosts: ipaserver
become: true
gather_facts: false
tasks:
- name: Include services.json
ansible.builtin.include_vars:
file: services.json # noqa 505
- name: Create dict with service names
ansible.builtin.set_fact:
services_names: "{{ services_names | default([]) + [{'name': item.name}] }}"
loop: "{{ service_list }}"
- name: Services absent len:{{ service_list | length }}
ipaservice:
ipaadmin_password: SomeADMINpassword
services: "{{ services_names }}"
state: absent
- name: Remove services.json
hosts: localhost
tasks:
- name: Remove services.json
ansible.builtin.file:
state: absent
path: services.json

View File

@@ -0,0 +1,39 @@
---
- name: Include create_services_json.yml
ansible.builtin.import_playbook: create_services_json.yml
- name: Test services present
hosts: ipaserver
become: true
gather_facts: false
tasks:
- name: Include services.json
ansible.builtin.include_vars:
file: services.json # noqa 505
- name: Include hosts.json
ansible.builtin.include_vars:
file: hosts.json # noqa 505
- name: Hosts present len:{{ host_list | length }}
ipahost:
ipaadmin_password: SomeADMINpassword
hosts: "{{ host_list }}"
- name: Services present len:{{ service_list | length }}
ipaservice:
ipaadmin_password: SomeADMINpassword
services: "{{ service_list }}"
- name: Remove services.json
hosts: localhost
tasks:
- name: Remove services.json
ansible.builtin.file:
state: absent
path: services.json
- name: Remove hosts.json
ansible.builtin.file:
state: absent
path: hosts.json

View File

@@ -0,0 +1,46 @@
---
- name: Include create_services_json.yml
ansible.builtin.import_playbook: create_services_json.yml
- name: Test services present slice
hosts: ipaserver
become: true
gather_facts: false
vars:
slice_size: 500
tasks:
- name: Include services.json
ansible.builtin.include_vars:
file: services.json # noqa 505
- name: Include hosts.json
ansible.builtin.include_vars:
file: hosts.json # noqa 505
- name: Size of services slice.
ansible.builtin.debug:
msg: "{{ service_list | length }}"
- name: Size of hosts slice.
ansible.builtin.debug:
msg: "{{ host_list | length }}"
- name: Hosts present
ipahost:
ipaadmin_password: SomeADMINpassword
hosts: "{{ host_list[item : item + slice_size] }}"
loop: "{{ range(0, service_list | length, slice_size) | list }}"
- name: Services present
ipaservice:
ipaadmin_password: SomeADMINpassword
services: "{{ service_list[item : item + slice_size] }}"
loop: "{{ range(0, service_list | length, slice_size) | list }}"
- name: Remove services.json
hosts: localhost
tasks:
- name: Remove services.json
ansible.builtin.file:
state: absent
path: services.json
- name: Remove hosts.json
ansible.builtin.file:
state: absent
path: hosts.json

View File

@@ -0,0 +1,100 @@
---
- name: Test services without using option skip_host_check
hosts: ipaserver
become: true
tasks:
# setup
- name: Test services without using option skip_host_check
block:
- name: Setup test environment
ansible.builtin.include_tasks: env_setup.yml
- name: Services are present
ipaservice:
ipaadmin_password: SomeADMINpassword
services:
- name: "HTTP/{{ svc_fqdn }}"
principal:
- host/test.example.com
- name: "mysvc/{{ host1_fqdn }}"
pac_type: NONE
ok_as_delegate: yes
ok_to_auth_as_delegate: yes
- name: "HTTP/{{ host1_fqdn }}"
allow_create_keytab_user:
- user01
- user02
allow_create_keytab_group:
- group01
- group02
allow_create_keytab_host:
- "{{ host1_fqdn }}"
- "{{ host2_fqdn }}"
allow_create_keytab_hostgroup:
- hostgroup01
- hostgroup02
- name: "mysvc/{{ host2_fqdn }}"
auth_ind: otp,radius
register: result
failed_when: not result.changed or result.failed
- name: Services are present again
ipaservice:
ipaadmin_password: SomeADMINpassword
services:
- name: "HTTP/{{ svc_fqdn }}"
- name: "mysvc/{{ host1_fqdn }}"
- name: "HTTP/{{ host1_fqdn }}"
- name: "mysvc/{{ host2_fqdn }}"
register: result
failed_when: result.changed or result.failed
# failed_when: not result.failed has been added as this test needs to
# fail because two services with the same name should be added in the same
# task.
- name: Duplicate names in services failure test
ipaservice:
ipaadmin_password: SomeADMINpassword
services:
- name: "HTTP/{{ svc_fqdn }}"
- name: "mysvc/{{ host1_fqdn }}"
- name: "HTTP/{{ nohost_fqdn }}"
- name: "HTTP/{{ svc_fqdn }}"
register: result
failed_when: result.changed or not result.failed or "is used more than once" not in result.msg
- name: Services/name and name 'service' present
ipaservice:
ipaadmin_password: SomeADMINpassword
name: "HTTP/{{ svc_fqdn }}"
services:
- name: "HTTP/{{ svc_fqdn }}"
register: result
failed_when: result.changed or not result.failed or "parameters are mutually exclusive" not in result.msg
- name: Services/name and name are absent
ipaservice:
ipaadmin_password: SomeADMINpassword
register: result
failed_when: result.changed or not result.failed or "one of the following is required" not in result.msg
- name: Name is absent
ipaservice:
ipaadmin_password: SomeADMINpassword
name:
register: result
failed_when: result.changed or not result.failed or "At least one name or services is required" not in result.msg
- name: Only one service can be added at a time using name.
ipaservice:
ipaadmin_password: SomeADMINpassword
name: example.com,example1.com
register: result
failed_when: result.changed or not result.failed or "Only one service can be added at a time using 'name'." not in result.msg
always:
# cleanup
- name: Cleanup test environment
ansible.builtin.include_tasks: env_cleanup.yml