mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-05-08 06:13:21 +00:00
The file lookup is by default setting `rstrip=True` which could lead into a stripped new line. This is not happening always but resulted in failed tests sometimes with certificates pasted to the b64encode filter. For calls of lookup in the certificae tests `rstrip=False` has been added to make sure that this is not happening any more. Not in test_dnsrecord as lookup(..., rstrip=False) is adding a new line if there was not a new line and this is an issue for dnsrecord. The user and host tests have also been simplified to create the base64 encoded file in the beginning and use this file then later on in the tests without the need to use the b64encode filter. Ref: https://github.com/ansible/ansible/issues/57521#issuecomment-502238000
110 lines
3.4 KiB
YAML
110 lines
3.4 KiB
YAML
---
|
|
- name: Test host certificates
|
|
hosts: ipaserver
|
|
become: true
|
|
|
|
tasks:
|
|
- name: Get Domain from server name
|
|
set_fact:
|
|
ipaserver_domain: "{{ ansible_fqdn.split('.')[1:] | join ('.') }}"
|
|
when: ipaserver_domain is not defined
|
|
|
|
- name: Generate self-signed certificates.
|
|
shell:
|
|
cmd: |
|
|
openssl req -x509 -newkey rsa:2048 -days 365 -nodes -keyout "private{{ item }}.key" -out "cert{{ item }}.pem" -subj '/CN=test'
|
|
openssl x509 -outform der -in "cert{{ item }}.pem" -out "cert{{ item }}.der"
|
|
base64 "cert{{ item }}.der" -w5000 > "cert{{ item }}.b64"
|
|
with_items: [1, 2, 3]
|
|
become: no
|
|
delegate_to: localhost
|
|
|
|
- name: Host test absent
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
name: "{{ 'test.' + ipaserver_domain }}"
|
|
state: absent
|
|
|
|
- name: Host test present
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
name: "{{ 'test.' + ipaserver_domain }}"
|
|
force: yes
|
|
register: result
|
|
failed_when: not result.changed
|
|
|
|
- name: Host test cert members present
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
name: "{{ 'test.' + ipaserver_domain }}"
|
|
certificate:
|
|
- "{{ lookup('file', 'cert1.b64', rstrip=False) }}"
|
|
- "{{ lookup('file', 'cert2.b64', rstrip=False) }}"
|
|
- "{{ lookup('file', 'cert3.b64', rstrip=False) }}"
|
|
action: member
|
|
register: result
|
|
failed_when: not result.changed
|
|
|
|
- name: Host test cert members present again
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
name: "{{ 'test.' + ipaserver_domain }}"
|
|
certificate:
|
|
- "{{ lookup('file', 'cert1.b64', rstrip=False) }}"
|
|
- "{{ lookup('file', 'cert2.b64', rstrip=False) }}"
|
|
- "{{ lookup('file', 'cert3.b64', rstrip=False) }}"
|
|
action: member
|
|
register: result
|
|
failed_when: result.changed
|
|
|
|
- name: Host test cert members absent
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
name: "{{ 'test.' + ipaserver_domain }}"
|
|
certificate:
|
|
- "{{ lookup('file', 'cert1.b64', rstrip=False) }}"
|
|
- "{{ lookup('file', 'cert2.b64', rstrip=False) }}"
|
|
- "{{ lookup('file', 'cert3.b64', rstrip=False) }}"
|
|
state: absent
|
|
action: member
|
|
register: result
|
|
failed_when: not result.changed
|
|
|
|
- name: Host test cert members absent again
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
name: "{{ 'test.' + ipaserver_domain }}"
|
|
certificate:
|
|
- "{{ lookup('file', 'cert1.b64', rstrip=False) }}"
|
|
- "{{ lookup('file', 'cert2.b64', rstrip=False) }}"
|
|
- "{{ lookup('file', 'cert3.b64', rstrip=False) }}"
|
|
state: absent
|
|
action: member
|
|
register: result
|
|
failed_when: result.changed
|
|
|
|
- name: Host test absent
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
name: "{{ 'test.' + ipaserver_domain }}"
|
|
state: absent
|
|
register: result
|
|
failed_when: not result.changed
|
|
|
|
- name: Host test absent again
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
name: "{{ 'test.' + ipaserver_domain }}"
|
|
state: absent
|
|
register: result
|
|
failed_when: result.changed
|
|
|
|
- name: Remove certificate files.
|
|
shell:
|
|
cmd: rm -f "private{{ item }}.key" "cert{{ item }}.pem" "cert{{ item }}.der" "cert{{ item }}.b64"
|
|
with_items: [1, 2, 3]
|
|
become: no
|
|
delegate_to: localhost
|
|
args:
|
|
warn: no # suppres warning for not using the `file` module.
|