-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
64 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
- name: Create a non-root sudoer user | ||
ansible.builtin.user: | ||
name: "{{ item.user }}" | ||
password: "{{ item.password }}" | ||
shell: /bin/bash | ||
create_home: yes | ||
|
||
- name: Grant user ability to run any command as sudo | ||
ansible.builtin.lineinfile: | ||
path: /etc/sudoers | ||
line: "{{ item.user }} ALL=(ALL) ALL" | ||
validate: "visudo -cf %s" | ||
|
||
- name: Create an .ssh directory | ||
ansible.builtin.file: | ||
path: "/home/{{ item.user }}/.ssh" | ||
state: directory | ||
mode: "0700" | ||
owner: "{{ item.user }}" | ||
|
||
- name: Configure SSH access for new user | ||
ansible.builtin.copy: | ||
src: "{{ molecule_ephemeral_directory }}/id_rsa.pub" | ||
dest: "/home/{{ item.user }}/.ssh/authorized_keys" | ||
mode: "0600" | ||
owner: "{{ item.user }}" | ||
|
||
- name: Edit SSH config to disallow root login | ||
ansible.builtin.lineinfile: | ||
path: /etc/ssh/sshd_config | ||
regexp: '^(#*)?PermitRootLogin' | ||
line: PermitRootLogin no | ||
|
||
- name: Restart SSH | ||
ansible.builtin.service: | ||
name: sshd | ||
state: restarted | ||
|
||
- name: Modify Molecule inventory | ||
ansible.builtin.lineinfile: | ||
path: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml" | ||
regexp: 'ansible_user:' | ||
line: "ansible_user: {{ item.user }}, ansible_become_password: {{ item.password }}}" | ||
delegate_to: localhost | ||
|
||
- name: Force refresh inventory | ||
ansible.builtin.meta: refresh_inventory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters