keytab: Try make code cleaner

This commit is contained in:
Timo Makinen 2025-01-30 20:05:47 +00:00
parent 872115a9a9
commit 981b954682
2 changed files with 38 additions and 41 deletions

View file

@ -0,0 +1 @@


View file

@ -5,50 +5,46 @@
register: keytab_status
check_mode: false
- name: Create temporary file
ansible.builtin.tempfile:
state: file
register: tempfile
when: not keytab_status.stat.exists
- name: Create keytab
block:
- name: Create temporary file
ansible.builtin.tempfile:
state: file
register: tempfile
- name: Initialize keytab
ansible.builtin.copy:
dest: tempfile.path
content: "\\0005\\0002\\c"
mode: "0600"
owner: root
group: "{{ ansible_wheel }}"
when: not keytab_status.stat.exists
- name: Initialize keytab
ansible.builtin.copy:
dest: "{{ tempfile.path }}"
src: empty.keytab
mode: "0600"
owner: root
group: "{{ ansible_wheel }}"
- name: Add principal to keytab
ansible.builtin.command:
argv:
- kadmin.local
- -x
- host=ldaps://ldap01.foo.sh
- ktadd
- -k
- "{{ tempfile.path }}"
- "{{ item }}"
with_items: "{{ keytab_principals }}"
- name: Add principal to keytab
ansible.builtin.command:
argv:
- kadmin.local
- -x
- host=ldaps://ldap01.foo.sh
- ktadd
- -k
- "{{ tempfile.path }}"
- "{{ item }}"
with_items: "{{ keytab_principals }}"
- name: Get keytab
ansible.builtin.command:
argv:
- base64
- "{{ tempfile.path }}"
register: keytab_data
- name: Delete temporary file
ansible.builtin.file:
path: "{{ tempfile.path }}"
state: absent
when: not keytab_status.stat.exists
delegate_to: ldap01.home.foo.sh
when: not keytab_status.stat.exists
- name: Get keytab
ansible.builtin.command:
argv:
- base64
- "{{ tempfile.path }}"
register: keytab_data
delegate_to: ldap01.home.foo.sh
when: not keytab_status.stat.exists
- name: Delete temporary file
ansible.builtin.file:
path: "{{ tempfile.path }}"
state: absent
delegate_to: ldap01.home.foo.sh
when: not keytab_status.stat.exists
- name: Deploy keytab file
ansible.builtin.shell: >-