Skip to content

Commit

Permalink
Linux AD Join Role Updates (#374)
Browse files Browse the repository at this point in the history
* Add error handling
* New tag and user data to test ansible role



---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
pavmoj and github-actions[bot] authored Oct 24, 2023
1 parent efe2abb commit bc78b96
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
8 changes: 8 additions & 0 deletions ansible/group_vars/ami_hmpps_domain_services_rhel_8_5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
ansible_python_interpreter: python3.9

ami_roles_list:
- join-devtest-ad-linux

# the below vars are defined in multiple groups. Keep the values the same to avoid unexpected behaviour
roles_list: "{{ (ami_roles_list | default([]) | difference(server_type_roles_list | default([]))) + (server_type_roles_list | default([])) }}"
4 changes: 3 additions & 1 deletion ansible/group_vars/server_type_hmpps_domain_services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
ansible_python_interpreter: python3.9

server_type_roles_list:
- join-ad-linux
- join-devtest-ad-linux

roles_list: "{{ (ami_roles_list | default([]) | difference(server_type_roles_list | default([]))) + (server_type_roles_list | default([])) }}"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
---
- name: Check if instance is already joined to the domain
command: getent passwd {{ join_domain_linux_service_account_username }}@{{ ad_domain }}
changed_when: false
register: result
ignore_errors: yes

- name: Exit out of the play if instance is already joined to the domain
meta: end_host
when:
- result.rc == 0

- name: Configure sshd_config
lineinfile:
path: /etc/ssh/sshd_config
Expand Down Expand Up @@ -28,3 +39,13 @@
command: /bin/bash -c "/usr/sbin/realm join --user={{ join_domain_linux_service_account_username }}@{{ ad_domain|upper }} {{ ad_domain|lower }} -v"
responses:
Password for *: "{{ join_domain_linux_service_account_password }}"

- name: Validate the AD join
command: getent passwd {{ join_domain_linux_service_account_username }}@{{ ad_domain }}
register: result
ignore_errors: yes

- name: Check the validation result
fail:
msg: "AD join validation failed, {{ result.stderr }}"
when: result.rc != 0
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
---
- name: Set instance hostname
import_role:
name: set-ec2-hostname

- name: Get linux service account details
import_tasks: get_facts.yml
tags:
- ec2provision
when: ansible_distribution in ['RedHat']

- import_tasks: join_domain.yml
tags:
- ec2provision
when: ansible_distribution in ['RedHat']

0 comments on commit bc78b96

Please sign in to comment.