Skip to content

Commit

Permalink
Add the bastion host user creation tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
enasca committed Oct 20, 2023
1 parent b46ddb2 commit 25e98f9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ansible/playbooks/usermgmt/create-users-groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
tasks:
- name: Create users
ansible.builtin.include_tasks: tasks/add-user-ipa.yml
loop: "{{ hostvars['localhost']['userdata'] | dict2items }}"
when: hostvars['localhost']['userdata'] is defined
loop: "{{ hostvars['localhost']['userdata'] | default({}) | dict2items }}"

- name: Create groups
ansible.builtin.include_tasks: tasks/add-group-ipa.yml
loop: "{{ hostvars['localhost']['groupdata'] | dict2items }}"
when: hostvars['localhost']['groupdata'] is defined
loop: "{{ hostvars['localhost']['groupdata'] | default({}) | dict2items }}"

- hosts: bastion_hosts
gather_facts: false
tasks:
- name: Create users
ansible.builtin.include_tasks: tasks/add-user-bastion.yml
loop: "{{ hostvars['localhost']['userdata'] | default({}) | dict2items }}"
33 changes: 33 additions & 0 deletions ansible/playbooks/usermgmt/tasks/add-user-bastion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Create a temp file to hold the user data
ansible.builtin.tempfile:
prefix: "usermgmt."
suffix: ".userdata"
state: file
register: usermgmt_tempfile

- name: Populate the tempfile
vars:
user_list:
- username: "{{ item['value']['username'] }}"
ssh_public_key: "{{ item['value']['ssh_public_key'] | default([]) }}"
ansible.builtin.template:
dest: "{{ usermgmt_tempfile['path'] }}"
src: templates/usermgmt_file.j2
mode: "0600"
when: usermgmt_tempfile['path'] is defined

- name: Create the user on the bastion host
ansible.builtin.command:
argv:
- sudo
- /root/bin/ikimuseradd.sh
- "{{ usermgmt_tempfile['path'] }}"
creates: "/home/{{ item['value']['username'] }}"
when: usermgmt_tempfile['path'] is defined

- name: Delete the temp file
ansible.builtin.file:
path: "{{ usermgmt_tempfile['path'] }}"
state: absent
when: usermgmt_tempfile['path'] is defined

0 comments on commit 25e98f9

Please sign in to comment.