mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-03-26 21:33:05 +00:00
This patch adds Ansible tasks to create and remove self-signed certificates, instead of using previously created certificates. The certificates are then `lookup`, instead of being used inline in the playbooks. Playbooks are easier to read and maintain with this changes, and there is no need to change the playbooks, if a certificate expires.
64 lines
1.6 KiB
YAML
64 lines
1.6 KiB
YAML
---
|
|
- name: Test user certificates
|
|
hosts: ipaserver
|
|
become: true
|
|
gather_facts: false
|
|
|
|
tasks:
|
|
- 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"
|
|
with_items: [1, 2]
|
|
become: no
|
|
delegate_to: localhost
|
|
|
|
- name: User test absent
|
|
ipauser:
|
|
ipaadmin_password: SomeADMINpassword
|
|
users:
|
|
- name: test
|
|
state: absent
|
|
|
|
- name: User test present
|
|
ipauser:
|
|
ipaadmin_password: SomeADMINpassword
|
|
users:
|
|
- name: test
|
|
first: test
|
|
last: test
|
|
|
|
- name: User test cert members present
|
|
ipauser:
|
|
ipaadmin_password: SomeADMINpassword
|
|
users:
|
|
- name: test
|
|
certificate:
|
|
- "{{ lookup('file', 'cert1.der') | b64encode }}"
|
|
action: member
|
|
register: result
|
|
failed_when: not result.changed
|
|
|
|
- name: User test cert members absent
|
|
ipauser:
|
|
ipaadmin_password: SomeADMINpassword
|
|
users:
|
|
- name: test
|
|
certificate:
|
|
- "{{ lookup('file', 'cert1.der') | b64encode }}"
|
|
- "{{ lookup('file', 'cert2.der') | b64encode }}"
|
|
state: absent
|
|
action: member
|
|
#register: result
|
|
#failed_when: not result.changed
|
|
|
|
- name: Remove certificate files.
|
|
shell:
|
|
cmd: rm -f "private{{ item }}.key" "cert{{ item }}.pem" "cert{{ item }}.der"
|
|
with_items: [1, 2]
|
|
become: no
|
|
delegate_to: localhost
|
|
args:
|
|
warn: no # suppres warning for not using the `file` module.
|