ansible-role-ipa-getcert/tasks/main.yml

78 lines
2.8 KiB
YAML
Raw Normal View History

2020-12-19 06:19:07 +00:00
---
2020-12-19 08:54:17 +00:00
# Request the certificate for the host from IPA
# System must be enrolled as an IPA Client and must be ran as root
- name: Check if host is IPA enrolled
shell: /usr/sbin/ipa-client-install --unattended 2>&1 | grep "already configured"
register: ipacheck
ignore_errors: true
2020-12-20 01:40:30 +00:00
changed_when: false
2020-12-19 08:54:17 +00:00
2020-12-20 17:49:24 +00:00
- name: Verify host is IPA enrolled
2022-03-28 02:36:15 +00:00
ansible.builtin.assert:
2020-12-20 17:49:24 +00:00
that:
- ipacheck.rc == 0 | mandatory
fail_msg: "System is not enrolled to IPA"
success_msg: "IPA enrolled, moving on"
quiet: true
2020-12-19 08:54:17 +00:00
- name: IPA Certificate Operations
block:
2020-12-20 01:12:34 +00:00
- name: Deploy ipa-getcert script
2022-03-28 02:36:15 +00:00
ansible.builtin.template:
2020-12-20 01:12:34 +00:00
src: "get_cert.sh.j2"
dest: "/root/get_cert.sh"
2020-12-19 08:54:17 +00:00
owner: root
group: root
2020-12-20 01:12:34 +00:00
mode: '0750'
- name: Request Certificate
2022-03-28 02:36:15 +00:00
ansible.builtin.raw: /root/get_cert.sh
2020-12-20 01:12:34 +00:00
register: ipa_cert_request
2020-12-19 08:54:17 +00:00
- name: Chain link certificates
block:
- name: Create chain directory
2022-03-28 02:36:15 +00:00
ansible.builtin.file:
2020-12-19 08:54:17 +00:00
state: directory
path: "{{ ipa_getcert_chain_location }}"
owner: root
group: "{{ ipa_getcert_group }}"
mode: '0750'
- name: Chain link certs
2022-03-28 02:36:15 +00:00
ansible.builtin.file:
2020-12-19 08:54:17 +00:00
state: link
2020-12-20 01:12:34 +00:00
src: "{{ item.cert_location | default(ipa_getcert_cert_default_location) }}/{{ item.name }}.crt"
dest: "{{ ipa_getcert_chain_location }}/{{ item.name }}.crt"
owner: "{{ item.owner | default(ipa_getcert_owner_default) }}"
group: "{{ item.owner | default(ipa_getcert_owner_default) }}"
2020-12-19 08:54:17 +00:00
with_items: "{{ ipa_getcert_requested_hostnames }}"
- name: Chain link keys
2022-03-28 02:36:15 +00:00
ansible.builtin.file:
2020-12-19 08:54:17 +00:00
state: link
2020-12-20 01:12:34 +00:00
src: "{{ item.key_location | default(ipa_getcert_cert_default_location) }}/{{ item.name }}.key"
path: "{{ ipa_getcert_chain_location }}/{{ item.name }}.key"
owner: "{{ item.owner | default(ipa_getcert_owner_default) }}"
group: "{{ item.owner | default(ipa_getcert_owner_default) }}"
2020-12-19 08:54:17 +00:00
with_items: "{{ ipa_getcert_requested_hostnames }}"
- name: Assemble the chain
2022-03-28 02:36:15 +00:00
ansible.builtin.assemble:
2020-12-19 08:54:17 +00:00
src: "{{ ipa_getcert_chain_location }}"
2020-12-20 01:12:34 +00:00
dest: "{{ ipa_getcert_chain_location }}/{{ item.name }}.pem"
regexp: "^{{ item.name }}.(crt|key)$"
owner: "{{ item.owner | default(ipa_getcert_owner_default) }}"
group: "{{ item.owner | default(ipa_getcert_owner_default) }}"
2020-12-19 08:54:17 +00:00
mode: '0640'
with_items: "{{ ipa_getcert_requested_hostnames }}"
2020-12-20 01:40:30 +00:00
when:
2021-01-24 19:42:00 +00:00
- ipa_getcert_chain|bool
2020-12-20 01:40:30 +00:00
- ipa_cert_request.rc == 0
2020-12-20 01:45:49 +00:00
rescue:
- name: "Erroring out with message"
2022-03-28 02:36:15 +00:00
ansible.builtin.debug:
2020-12-20 01:45:49 +00:00
msg: "We caught an error, likely with the ipa-getcert script. Please verify the output."
2020-12-20 01:12:34 +00:00
when:
- ipacheck.rc == 0