Compare commits
No commits in common. "3b875f7c830e6be872d78c96f2010be8262100cd" and "master" have entirely different histories.
3b875f7c83
...
master
5
autopassword.sh
Normal file
5
autopassword.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
key=hello
|
||||||
|
name=$1
|
||||||
|
hash=$(echo -n "$name$key" | sha256sum | xxd -r -p | base64 | tr -d '+/')
|
||||||
|
echo "${hash:0:8}-${hash:8:8}"
|
@ -1,2 +1,3 @@
|
|||||||
- name: restart ufw
|
- name: restart ufw
|
||||||
service: name=ufw state=restarted
|
service: name=ufw state=restarted
|
||||||
|
become: yes
|
17
hosts
Normal file
17
hosts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[forensics]
|
||||||
|
10.8.2.12 ansible_user=administrator
|
||||||
|
|
||||||
|
[database]
|
||||||
|
10.8.2.3 ansible_user=administrator
|
||||||
|
|
||||||
|
[workstations]
|
||||||
|
10.8.1.10 ansible_user=administrator
|
||||||
|
10.8.1.40 ansible_user=administrator
|
||||||
|
|
||||||
|
[workstations:children]
|
||||||
|
web
|
||||||
|
|
||||||
|
[web]
|
||||||
|
10.8.1.90 ansible_user=administrator
|
||||||
|
|
||||||
|
|
8
roles/database/tasks/main.yml
Normal file
8
roles/database/tasks/main.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- name: Allow MySQL traffic
|
||||||
|
ufw: rule={{ item.rule }} port={{ item.port }} proto={{ item.proto }}
|
||||||
|
with_items:
|
||||||
|
- { rule: 'allow', port: '3306', proto: 'tcp' }
|
||||||
|
notify:
|
||||||
|
- restart ufw
|
||||||
|
become: yes
|
3
roles/immortal/handlers/main.yml
Normal file
3
roles/immortal/handlers/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
- name: restart ufw
|
||||||
|
service: name=ufw state=restarted
|
||||||
|
become: yes
|
@ -1,13 +1,14 @@
|
|||||||
---
|
---
|
||||||
- name: Generate password
|
# - name: Generate password
|
||||||
delegate_to: localhost
|
# delegate_to: localhost
|
||||||
shell: bash autopassword.sh {{ inventory_hostname }}
|
# shell: bash autopassword.sh {{ inventory_hostname }}
|
||||||
register: genPass
|
# register: genPass
|
||||||
|
|
||||||
- name: Backup ssh config
|
- name: Backup ssh config
|
||||||
fetch:
|
fetch:
|
||||||
src: /etc/ssh/sshd_config
|
src: /etc/ssh/sshd_config
|
||||||
dest: "{{ inventory_hostname }}"
|
dest: "{{ inventory_hostname }}"
|
||||||
|
become: yes
|
||||||
|
|
||||||
- name: Backup os-release
|
- name: Backup os-release
|
||||||
fetch:
|
fetch:
|
||||||
@ -19,11 +20,57 @@
|
|||||||
src: /etc/passwd
|
src: /etc/passwd
|
||||||
dest: "{{ inventory_hostname }}"
|
dest: "{{ inventory_hostname }}"
|
||||||
|
|
||||||
|
- name: Collect disk space data
|
||||||
|
block:
|
||||||
|
- name: lsblk
|
||||||
|
shell: lsblk
|
||||||
|
register: lsblk_output
|
||||||
|
become: yes
|
||||||
|
- name: Store results
|
||||||
|
copy:
|
||||||
|
content: "{{lsblk_output.stdout}}"
|
||||||
|
dest: "{{ inventory_hostname }}/lsblk.out"
|
||||||
|
delegate_to: localhost
|
||||||
|
become: no
|
||||||
|
|
||||||
|
- name: Collect netstat
|
||||||
|
block:
|
||||||
|
- name: Run command
|
||||||
|
shell: netstat -peanut
|
||||||
|
register: netstat_output
|
||||||
|
become: yes
|
||||||
|
- name: Store results
|
||||||
|
copy:
|
||||||
|
content: "{{netstat_output.stdout}}"
|
||||||
|
dest: "{{ inventory_hostname }}/netstat.out"
|
||||||
|
delegate_to: localhost
|
||||||
|
become: no
|
||||||
|
- name: Collect process data
|
||||||
|
block:
|
||||||
|
- name: Run command
|
||||||
|
shell: ps aux
|
||||||
|
register: ps_output
|
||||||
|
become: yes
|
||||||
|
- name: Store results
|
||||||
|
copy:
|
||||||
|
content: "{{ps_output.stdout}}"
|
||||||
|
dest: "{{ inventory_hostname }}/ps.out"
|
||||||
|
delegate_to: localhost
|
||||||
|
become: no
|
||||||
- name: Get users
|
- name: Get users
|
||||||
get_users:
|
get_users:
|
||||||
min_uid: {{ (ansible_os_family == 'RedHat') | ternary(500,1000) }}
|
#min_uid: "{{ (ansible_os_family == 'RedHat') | ternary(500,1000) }}"
|
||||||
|
min_uid: 1000
|
||||||
max_uid: 65000
|
max_uid: 65000
|
||||||
register: users_list
|
become: yes
|
||||||
|
register: users_list
|
||||||
|
|
||||||
|
- name: Backup all users authorized keys
|
||||||
|
fetch:
|
||||||
|
src: "{{item['dir']}}/.ssh/authorized_keys"
|
||||||
|
dest: "{{ inventory_hostname }}"
|
||||||
|
ignore_errors: yes
|
||||||
|
loop: "{{ users_list.users }}"
|
||||||
|
|
||||||
- name: Give root exclusively the current controller user's SSH key
|
- name: Give root exclusively the current controller user's SSH key
|
||||||
ansible.posix.authorized_key:
|
ansible.posix.authorized_key:
|
||||||
@ -31,54 +78,72 @@
|
|||||||
state: present
|
state: present
|
||||||
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
|
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
|
||||||
exclusive: yes
|
exclusive: yes
|
||||||
become: yes
|
become: yes
|
||||||
|
|
||||||
|
|
||||||
- name: Give all users exclusively the current controller user's SSH key
|
- name: Give all users exclusively the current controller user's SSH key
|
||||||
ansible.posix.authorized_key:
|
ansible.posix.authorized_key:
|
||||||
user: {{item}}
|
user: "{{item['name']}}"
|
||||||
state: present
|
state: present
|
||||||
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
|
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
|
||||||
exclusive: yes
|
exclusive: yes
|
||||||
become: yes
|
become: yes
|
||||||
loop: "{{ users_list.users }}"
|
loop: "{{ users_list.users }}"
|
||||||
|
|
||||||
- name: Ensure UFW is installed
|
- block:
|
||||||
package:
|
- name: Ensure EPEL if RHEL based
|
||||||
name: ufw
|
yum:
|
||||||
state: present
|
name: epel-release
|
||||||
|
state: present
|
||||||
|
when: ansible_os_family == "RedHat"
|
||||||
|
|
||||||
- name: Configure ufw defaults
|
- name: Disable firewalld if RHEL based
|
||||||
ufw: direction={{ item.direction }} policy={{ item.policy }}
|
shell: "systemctl disable firewalld; systemctl stop firewalld"
|
||||||
with_items:
|
when: ansible_os_family == "RedHat"
|
||||||
- { direction: 'incoming', policy: 'deny' }
|
|
||||||
- { direction: 'outgoing', policy: 'allow' }
|
- name: Ensure UFW is installed
|
||||||
notify:
|
package:
|
||||||
- restart ufw
|
name: ufw
|
||||||
|
state: present
|
||||||
|
|
||||||
- name: Configure ufw rules
|
- name: Ensure UFW is disabled
|
||||||
ufw: rule={{ item.rule }} port={{ item.port }} proto={{ item.proto }}
|
ufw: state=disabled
|
||||||
with_items:
|
|
||||||
- { rule: 'limit', port: '22', proto: 'tcp' }
|
- name: Reset UFW
|
||||||
notify:
|
ufw: state=reset
|
||||||
- restart ufw
|
|
||||||
|
|
||||||
- name: Enable ufw logging
|
- name: Configure ufw defaults
|
||||||
ufw: logging=on
|
ufw: direction={{ item.direction }} policy={{ item.policy }}
|
||||||
notify:
|
with_items:
|
||||||
- restart ufw
|
- { direction: 'incoming', policy: 'deny' }
|
||||||
|
- { direction: 'outgoing', policy: 'allow' }
|
||||||
|
notify:
|
||||||
|
- restart ufw
|
||||||
|
|
||||||
- name: Enable ufw
|
- name: Configure ufw rules
|
||||||
ufw: state=enabled
|
ufw: rule={{ item.rule }} port={{ item.port }} proto={{ item.proto }}
|
||||||
|
with_items:
|
||||||
|
- { rule: 'limit', port: '22', proto: 'tcp' }
|
||||||
|
notify:
|
||||||
|
- restart ufw
|
||||||
|
|
||||||
- name: Change root password
|
- name: Enable ufw logging
|
||||||
user:
|
ufw: logging=on
|
||||||
name: root
|
notify:
|
||||||
shell: /bin/bash
|
- restart ufw
|
||||||
password: "{{ genPass.stdout | password_hash('sha512') }}"
|
|
||||||
|
|
||||||
- name: Change admin password
|
- name: Enable ufw
|
||||||
user:
|
ufw: state=enabled
|
||||||
name: "{{ ansible_user }}"
|
|
||||||
shell: /bin/bash
|
- name: Change root password
|
||||||
password: "{{ genPass.stdout | password_hash('sha512') }}"
|
user:
|
||||||
|
name: root
|
||||||
|
shell: /bin/bash
|
||||||
|
password: "{{ password | password_hash('sha512') }}"
|
||||||
|
|
||||||
|
- name: Change admin password
|
||||||
|
user:
|
||||||
|
name: "{{ ansible_user }}"
|
||||||
|
shell: /bin/bash
|
||||||
|
password: "{{ password | password_hash('sha512') }}"
|
||||||
|
become: yes
|
||||||
|
8
roles/web/tasks/main.yml
Normal file
8
roles/web/tasks/main.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- name: Allow Web traffic
|
||||||
|
ufw: rule={{ item.rule }} port={{ item.port }} proto={{ item.proto }}
|
||||||
|
with_items:
|
||||||
|
- { rule: 'allow', port: '80', proto: 'tcp' }
|
||||||
|
notify:
|
||||||
|
- restart ufw
|
||||||
|
become: yes
|
37
setup.yml
37
setup.yml
@ -1,4 +1,35 @@
|
|||||||
---
|
---
|
||||||
hosts: all
|
|
||||||
roles:
|
- hosts: all
|
||||||
- immortal
|
handlers:
|
||||||
|
- import_tasks: handlers.yml
|
||||||
|
vars_prompt:
|
||||||
|
- name: password
|
||||||
|
prompt: "Enter new root and admin password"
|
||||||
|
roles:
|
||||||
|
- immortal
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- hosts: web
|
||||||
|
handlers:
|
||||||
|
- import_tasks: handlers.yml
|
||||||
|
roles:
|
||||||
|
- web
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- hosts: database
|
||||||
|
handlers:
|
||||||
|
- import_tasks: handlers.yml
|
||||||
|
roles:
|
||||||
|
- database
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
- hosts: all
|
||||||
|
vars:
|
||||||
|
pip_install_packages:
|
||||||
|
- name: docker
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- geerlingguy.pip
|
||||||
|
- geerlingguy.docker
|
||||||
|
become: yes
|
Loading…
Reference in New Issue
Block a user