keytab: Try make code cleaner
This commit is contained in:
parent
872115a9a9
commit
981b954682
2 changed files with 38 additions and 41 deletions
1
roles/keytab/files/empty.keytab
Normal file
1
roles/keytab/files/empty.keytab
Normal file
|
@ -0,0 +1 @@
|
|||
|
|
@ -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: >-
|
||||
|
|
Loading…
Add table
Reference in a new issue