keytab: Don't use hardcoded tempfile

This commit is contained in:
Timo Makinen 2025-01-30 19:32:52 +00:00
parent 243574e415
commit 872115a9a9

View file

@ -5,6 +5,21 @@
register: keytab_status
check_mode: false
- name: Create temporary file
ansible.builtin.tempfile:
state: file
register: tempfile
when: not keytab_status.stat.exists
- 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: Add principal to keytab
ansible.builtin.command:
argv:
@ -13,7 +28,7 @@
- host=ldaps://ldap01.foo.sh
- ktadd
- -k
- "/tmp/{{ inventory_hostname }}.kt"
- "{{ tempfile.path }}"
- "{{ item }}"
with_items: "{{ keytab_principals }}"
delegate_to: ldap01.home.foo.sh
@ -23,14 +38,14 @@
ansible.builtin.command:
argv:
- base64
- "/tmp/{{ inventory_hostname }}.kt"
- "{{ 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: "/tmp/{{ inventory_hostname }}.kt"
path: "{{ tempfile.path }}"
state: absent
delegate_to: ldap01.home.foo.sh
when: not keytab_status.stat.exists