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,20 +5,20 @@
register: keytab_status register: keytab_status
check_mode: false check_mode: false
- name: Create keytab
block:
- name: Create temporary file - name: Create temporary file
ansible.builtin.tempfile: ansible.builtin.tempfile:
state: file state: file
register: tempfile register: tempfile
when: not keytab_status.stat.exists
- name: Initialize keytab - name: Initialize keytab
ansible.builtin.copy: ansible.builtin.copy:
dest: tempfile.path dest: "{{ tempfile.path }}"
content: "\\0005\\0002\\c" src: empty.keytab
mode: "0600" mode: "0600"
owner: root owner: root
group: "{{ ansible_wheel }}" group: "{{ ansible_wheel }}"
when: not keytab_status.stat.exists
- name: Add principal to keytab - name: Add principal to keytab
ansible.builtin.command: ansible.builtin.command:
@ -31,8 +31,6 @@
- "{{ tempfile.path }}" - "{{ tempfile.path }}"
- "{{ item }}" - "{{ item }}"
with_items: "{{ keytab_principals }}" with_items: "{{ keytab_principals }}"
delegate_to: ldap01.home.foo.sh
when: not keytab_status.stat.exists
- name: Get keytab - name: Get keytab
ansible.builtin.command: ansible.builtin.command:
@ -40,15 +38,13 @@
- base64 - base64
- "{{ tempfile.path }}" - "{{ tempfile.path }}"
register: keytab_data register: keytab_data
delegate_to: ldap01.home.foo.sh
when: not keytab_status.stat.exists
- name: Delete temporary file - name: Delete temporary file
ansible.builtin.file: ansible.builtin.file:
path: "{{ tempfile.path }}" path: "{{ tempfile.path }}"
state: absent state: absent
delegate_to: ldap01.home.foo.sh
when: not keytab_status.stat.exists when: not keytab_status.stat.exists
delegate_to: ldap01.home.foo.sh
- name: Deploy keytab file - name: Deploy keytab file
ansible.builtin.shell: >- ansible.builtin.shell: >-