core: Swap to ansible roles for config
Signed-off-by: Noah Knegt <git@noahknegt.com>
This commit is contained in:
24
roles/base/tasks/main.yml
Normal file
24
roles/base/tasks/main.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
#===================================================================================================
|
||||
# ? ABOUT
|
||||
# @author : Noah Knegt
|
||||
# @email : personal@noahknegt.com
|
||||
# @repo : https://git.noahknegt.com/noah.knegt/ansible-automations
|
||||
# @createdOn : 27-02-2023
|
||||
# @description : This file contains the tasks for the base role, this role will be applied to
|
||||
# all machines.
|
||||
#===================================================================================================
|
||||
|
||||
---
|
||||
- include_vars: "{{ ansible_distribution }}.yml"
|
||||
|
||||
- block:
|
||||
# Setup the ansible user
|
||||
- include_tasks: users/ansible.yml
|
||||
- include_tasks: users/noahk.yml
|
||||
|
||||
# Setup the sshd
|
||||
- include_tasks: system/openssh.yml
|
||||
|
||||
# Setup the repositories for Debian based systems
|
||||
- include_tasks: software/repositories.yml
|
||||
|
17
roles/base/tasks/software/repositories.yml
Normal file
17
roles/base/tasks/software/repositories.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
#===================================================================================================
|
||||
# ? ABOUT
|
||||
# @author : Noah Knegt
|
||||
# @email : personal@noahknegt.com
|
||||
# @repo : https://git.noahknegt.com/noah.knegt/ansible-automations
|
||||
# @createdOn : 27-02-2023
|
||||
# @description : This will contain all the default software for the machines.
|
||||
#===================================================================================================
|
||||
|
||||
---
|
||||
- name: Install aptitude and software-properties-common
|
||||
package:
|
||||
name:
|
||||
- aptitude
|
||||
- software-properties-common
|
||||
state: latest
|
||||
when: ansible_distribution in ["Debian", "Pop!_OS", "Ubuntu"]
|
40
roles/base/tasks/system/openssh.yml
Normal file
40
roles/base/tasks/system/openssh.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
#===================================================================================================
|
||||
# ? ABOUT
|
||||
# @author : Noah Knegt
|
||||
# @email : personal@noahknegt.com
|
||||
# @repo : https://git.noahknegt.com/noah.knegt/ansible-automations
|
||||
# @createdOn : 27-02-2023
|
||||
# @description : This will setup the ssh server on the machine.
|
||||
#===================================================================================================
|
||||
|
||||
---
|
||||
- name: Install or update openssh
|
||||
apt:
|
||||
name: "{{ openssh_package }}"
|
||||
state: latest
|
||||
notify:
|
||||
- restart_sshd
|
||||
|
||||
- name: enable ssh daemon
|
||||
service:
|
||||
name: "{{ openssh_service }}"
|
||||
state: started
|
||||
enabled: yes
|
||||
|
||||
- name: configure sshd
|
||||
template:
|
||||
src: sshd_config.j2
|
||||
dest: /etc/ssh/sshd_config
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify:
|
||||
- restart_sshd
|
||||
|
||||
- name: copy sshd banner
|
||||
copy:
|
||||
src: ssh_banner.net
|
||||
dest: /etc/issue.net
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
48
roles/base/tasks/users/ansible.yml
Normal file
48
roles/base/tasks/users/ansible.yml
Normal file
@@ -0,0 +1,48 @@
|
||||
#===================================================================================================
|
||||
# ? ABOUT
|
||||
# @author : Noah Knegt
|
||||
# @email : personal@noahknegt.com
|
||||
# @repo : https://git.noahknegt.com/noah.knegt/ansible-automations
|
||||
# @createdOn : 27-02-2023
|
||||
# @description : It contains the tasks to properly configure the ansible user.
|
||||
#===================================================================================================
|
||||
|
||||
---
|
||||
- name: Add ansible group
|
||||
group:
|
||||
name: ansible
|
||||
state: present
|
||||
|
||||
- name: Add new ansible user
|
||||
user:
|
||||
name: ansible
|
||||
group: ansible
|
||||
groups: ansible,{{ sudo_group }}
|
||||
password: "{{ ansible_password }}"
|
||||
state: present
|
||||
shell: /bin/bash
|
||||
|
||||
- name: Add ansible user to sudoers
|
||||
copy:
|
||||
src: files/ansible_sudoers
|
||||
dest: /etc/sudoers.d/ansible
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0440
|
||||
|
||||
- name: Create .ssh directory
|
||||
file:
|
||||
path: /home/ansible/.ssh
|
||||
state: directory
|
||||
owner: ansible
|
||||
group: ansible
|
||||
mode: 0700
|
||||
with_items:
|
||||
- { dir: /home/ansible/.ssh }
|
||||
|
||||
- name: Copy ssh public key
|
||||
authorized_key:
|
||||
user: ansible
|
||||
key: "{{ item }}"
|
||||
with_file:
|
||||
- ansible/ansible.pub
|
48
roles/base/tasks/users/noahk.yml
Normal file
48
roles/base/tasks/users/noahk.yml
Normal file
@@ -0,0 +1,48 @@
|
||||
#===================================================================================================
|
||||
# ? ABOUT
|
||||
# @author : Noah Knegt
|
||||
# @email : personal@noahknegt.com
|
||||
# @repo : https://git.noahknegt.com/noah.knegt/ansible-automations
|
||||
# @createdOn : 27-02-2023
|
||||
# @description : This will setup the normal user on the machine.
|
||||
#===================================================================================================
|
||||
|
||||
---
|
||||
- name: Create the group
|
||||
group:
|
||||
name: noahk
|
||||
state: present
|
||||
|
||||
- name: Create the user
|
||||
user:
|
||||
name: noahk
|
||||
group: noahk
|
||||
groups: noahk,{{ sudo_group }}
|
||||
password: "{{ noahk_password }}"
|
||||
state: present
|
||||
shell: /bin/bash
|
||||
|
||||
- name: Add user to sudoers
|
||||
copy:
|
||||
src: files/noahk_sudoers
|
||||
dest: /etc/sudoers.d/noahk
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0440
|
||||
|
||||
- name: Create .ssh directory
|
||||
file:
|
||||
path: /home/noahk/.ssh
|
||||
state: directory
|
||||
owner: noahk
|
||||
group: noahk
|
||||
mode: 0700
|
||||
with_items:
|
||||
- { dir: /home/noahk/.ssh }
|
||||
|
||||
- name: Copy ssh public key
|
||||
authorized_key:
|
||||
user: noahk
|
||||
key: "{{ item }}"
|
||||
with_file:
|
||||
- noahk/noahk.pub
|
Reference in New Issue
Block a user