Compare commits
10 Commits
7b972c9f81
...
26b9453a8b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26b9453a8b | ||
|
|
7a87b6eb6b | ||
|
|
58a5941fdb | ||
|
|
eb0c5417d8 | ||
|
|
859119856e | ||
|
|
9733adc14b | ||
|
|
c5ec3e8f5c | ||
|
|
4c5609b990 | ||
|
|
9dbc688171 | ||
|
|
d393ba8b57 |
27
.gitignore
vendored
Normal file
27
.gitignore
vendored
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/ansible,visualstudiocode
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=ansible,visualstudiocode
|
||||||
|
|
||||||
|
### Ansible ###
|
||||||
|
*.retry
|
||||||
|
|
||||||
|
### VisualStudioCode ###
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
!.vscode/*.code-snippets
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Built Visual Studio Code Extensions
|
||||||
|
*.vsix
|
||||||
|
|
||||||
|
### VisualStudioCode Patch ###
|
||||||
|
# Ignore all local history of files
|
||||||
|
.history
|
||||||
|
.ionide
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/ansible,visualstudiocode
|
||||||
|
|
||||||
10
ansible.cfg
10
ansible.cfg
@@ -1,5 +1,15 @@
|
|||||||
[defaults]
|
[defaults]
|
||||||
|
# hosts file path
|
||||||
inventory = hosts
|
inventory = hosts
|
||||||
|
# number of hosts executed in parallel
|
||||||
|
forks = 20
|
||||||
|
# show execution time
|
||||||
|
callbacks_enabled = timer, profile_tasks, profile_roles
|
||||||
|
# reduce number of parallel ssh connections to one host
|
||||||
|
pipelining = True
|
||||||
|
interpreter_python = auto_silent
|
||||||
|
[ssh_connection]
|
||||||
|
ssh_args = -o ControlMaster=auto -o ControlPersist=40s
|
||||||
# (boolean) By default Ansible will issue a warning when received from a task action (module or action plugin)
|
# (boolean) By default Ansible will issue a warning when received from a task action (module or action plugin)
|
||||||
# These warnings can be silenced by adjusting this setting to False.
|
# These warnings can be silenced by adjusting this setting to False.
|
||||||
;action_warnings=True
|
;action_warnings=True
|
||||||
|
|||||||
24
hosts
24
hosts
@@ -1,23 +1,27 @@
|
|||||||
[desktop]
|
[desktop]
|
||||||
|
# dont put localhost here, ansible will attempt to connect via ssh
|
||||||
|
|
||||||
[headless]
|
[headless]
|
||||||
server[1:7]_oracle
|
server[1:4]
|
||||||
|
|
||||||
[oracleServer]
|
[oracle]
|
||||||
server[1:7]_oracle
|
server[1:4]
|
||||||
|
|
||||||
[home]
|
[home]
|
||||||
|
|
||||||
[ubuntu]
|
[debian]
|
||||||
server[1:7]_oracle
|
server[1:4]
|
||||||
|
jojo
|
||||||
|
|
||||||
[arm64]
|
[arm64]
|
||||||
server[2:6:2]_oracle
|
server2
|
||||||
server7_oracle
|
server4
|
||||||
|
|
||||||
[amd64]
|
[amd64]
|
||||||
server[1:5:2]_oracle
|
server1
|
||||||
|
server3
|
||||||
|
jojo
|
||||||
|
|
||||||
[prod]
|
[prod]
|
||||||
server1_oracle
|
jojo
|
||||||
server2_oracle
|
server4
|
||||||
|
|||||||
@@ -8,6 +8,6 @@
|
|||||||
include_role:
|
include_role:
|
||||||
name: force_limitArg
|
name: force_limitArg
|
||||||
|
|
||||||
- name: Reboot if required
|
- name: Install Docker Compose
|
||||||
include_role:
|
include_role:
|
||||||
name: install_dockerCompose
|
name: install_dockerCompose
|
||||||
8
install_dotfiles.yml
Normal file
8
install_dotfiles.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- name: Install dotfiles on target
|
||||||
|
hosts: 'kali'
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: Install dotfiles
|
||||||
|
include_role:
|
||||||
|
name: install_dotfiles
|
||||||
12
local.yml
12
local.yml
@@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
- hosts: localhost
|
|
||||||
tags:
|
|
||||||
become:
|
|
||||||
pre_tasks:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- hosts:
|
|
||||||
tags:
|
|
||||||
become:
|
|
||||||
roles:
|
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
---
|
---
|
||||||
- name: update apt-cache and upgrade
|
- name: Update apt-cache and upgrade
|
||||||
hosts: oracleServer
|
hosts: all
|
||||||
tasks:
|
tasks:
|
||||||
- name: upgrade packages
|
- name: Upgrade packages
|
||||||
become: true
|
become: true
|
||||||
package:
|
ansible.builtin.package:
|
||||||
update_cache: yes
|
update_cache: true
|
||||||
upgrade: 'yes'
|
upgrade: true
|
||||||
|
|
||||||
|
|||||||
17
requirements.yml
Normal file
17
requirements.yml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
roles:
|
||||||
|
- name: jan_matthis.git_dotfiles
|
||||||
|
- name: geerlingguy.docker
|
||||||
|
version: "6.1.0"
|
||||||
|
- name: geerlingguy.git
|
||||||
|
version: "3.1.0"
|
||||||
|
- name: geerlingguy.pip
|
||||||
|
version: "2.2.0"
|
||||||
|
- name: geerlingguy.nginx
|
||||||
|
version: "3.1.4"
|
||||||
|
|
||||||
|
collections:
|
||||||
|
- name: oracle.oci
|
||||||
|
version: "4.18.0"
|
||||||
|
- name: community.docker
|
||||||
|
version: "3.4.3"
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
- gnupg
|
- gnupg
|
||||||
- lsb-release
|
- lsb-release
|
||||||
state: latest
|
state: latest
|
||||||
update_cache: yes
|
update_cache: true
|
||||||
|
|
||||||
- name: Add Docker GPG Key
|
- name: Add Docker GPG Key
|
||||||
become: true
|
become: true
|
||||||
@@ -19,13 +19,13 @@
|
|||||||
- name: Add Docker Repository
|
- name: Add Docker Repository
|
||||||
become: true
|
become: true
|
||||||
apt_repository:
|
apt_repository:
|
||||||
repo: "deb [arch={{ arch }}] https://download.docker.com/linux/{{ansible_distribution|lower}} {{ansible_distribution_release}} stable"
|
repo: "deb [arch={{ arch }}] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} {{ release_branch_docker }}"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Install Docker packages
|
- name: Install Docker packages
|
||||||
become: true
|
become: true
|
||||||
apt:
|
apt:
|
||||||
update_cache: yes
|
update_cache: true
|
||||||
pkg:
|
pkg:
|
||||||
- docker-ce
|
- docker-ce
|
||||||
- docker-ce-cli
|
- docker-ce-cli
|
||||||
@@ -39,9 +39,9 @@
|
|||||||
name: "{{ ansible_user_id }}"
|
name: "{{ ansible_user_id }}"
|
||||||
groups:
|
groups:
|
||||||
- docker
|
- docker
|
||||||
append: yes
|
append: true
|
||||||
|
|
||||||
- name: Create docker folder in home directory
|
- name: Create docker folder in home directory
|
||||||
file:
|
file:
|
||||||
path: "{{ansible_user_dir}}/docker"
|
path: "{{ ansible_user_dir }}/docker"
|
||||||
state: directory
|
state: directory
|
||||||
|
|||||||
22
roles/install_dotfiles/defaults/main.yml
Normal file
22
roles/install_dotfiles/defaults/main.yml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# The git source of your dotfiles. Will be cloned as a bare repository.
|
||||||
|
# Make sure you have set up git correctly before using.
|
||||||
|
dotfiles_repo_source: "https://github.com/eneller/.dotfiles.git"
|
||||||
|
|
||||||
|
# can be branch name or commit hash, used for ansible.builtin.git version
|
||||||
|
dotfiles_repo_version: "headless"
|
||||||
|
|
||||||
|
# Will become the parent-directory of your dotfiles
|
||||||
|
dotfiles_dest: "{{ ansible_user_dir }}"
|
||||||
|
|
||||||
|
# The folder name to use for the bare repository
|
||||||
|
dotfiles_git_dir: "{{ ansible_user_dir}}/.dotfiles"
|
||||||
|
|
||||||
|
# Decide whether to back up already existing dotfiles that would conflict with your repo.
|
||||||
|
# Will overwrite them if false
|
||||||
|
dotfiles_do_backup: true
|
||||||
|
|
||||||
|
# Uses a temporary directory to run git ls-files if {{ dotfiles_do_backup }} is true
|
||||||
|
dotfiles_tmp_dir: "/tmp/dotfiles"
|
||||||
|
|
||||||
|
# An alias to access the bare repo for internal use
|
||||||
|
dotfiles_alias: "git --git-dir={{ dotfiles_git_dir }} --work-tree={{ dotfiles_dest }}"
|
||||||
54
roles/install_dotfiles/tasks/main.yml
Normal file
54
roles/install_dotfiles/tasks/main.yml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
- name: Check for existing dotfiles repository
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: "{{ dotfiles_git_dir }}/HEAD"
|
||||||
|
register: dotfiles_repo_head
|
||||||
|
changed_when: false # this never applies changes
|
||||||
|
when: dotfiles_do_backup
|
||||||
|
|
||||||
|
- name: Clone into /tmp
|
||||||
|
ansible.builtin.git:
|
||||||
|
dest: "{{ dotfiles_tmp_dir }}"
|
||||||
|
repo: "{{ dotfiles_repo_source }}"
|
||||||
|
version: "{{ dotfiles_repo_version }}"
|
||||||
|
when: not dotfiles_repo_head.stat.exists
|
||||||
|
|
||||||
|
|
||||||
|
- name: Get list of dotfiles
|
||||||
|
ansible.builtin.command:
|
||||||
|
chdir: "{{ dotfiles_tmp_dir }}"
|
||||||
|
cmd: git ls-files
|
||||||
|
register: dotfiles_lsfiles # needs to be used with .stdout_lines for iteratio
|
||||||
|
when: not dotfiles_repo_head.stat.exists
|
||||||
|
|
||||||
|
- name: Back up dotfiles that would be overwritten by checkout
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: "mv {{ dotfiles_dest }}/{{ item }} {{ dotfiles_dest }}/{{ item }}.bak"
|
||||||
|
args:
|
||||||
|
creates: "{{ dotfiles_dest }}/{{ item }}.bak"
|
||||||
|
removes: "{{ dotfiles_dest }}/{{ item }}"
|
||||||
|
with_items: "{{ dotfiles_lsfiles.stdout_lines }}"
|
||||||
|
when: not dotfiles_repo_head.stat.exists
|
||||||
|
|
||||||
|
- name: Initialize dotfiles repository in user home
|
||||||
|
ansible.builtin.git:
|
||||||
|
bare: true
|
||||||
|
update: true
|
||||||
|
force: true # this is okay here because we backed up already existing files
|
||||||
|
dest: "{{ dotfiles_git_dir }}"
|
||||||
|
repo: "{{ dotfiles_repo_source }}"
|
||||||
|
version: "{{ dotfiles_repo_version }}"
|
||||||
|
|
||||||
|
# TODO improve these cmd tasks, i dont really know how though
|
||||||
|
# i dont know why this checkout is necessary, was expecting the previous task to do this
|
||||||
|
- name: Configure git repository
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: |
|
||||||
|
{{ dotfiles_alias }}
|
||||||
|
checkout {{ dotfiles_repo_version }}
|
||||||
|
--force
|
||||||
|
|
||||||
|
- name: Configure git repository
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: |
|
||||||
|
{{ dotfiles_alias }}
|
||||||
|
config status.showUntrackedFiles no
|
||||||
21
ssh_addKey.yml
Normal file
21
ssh_addKey.yml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
# https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html#examples
|
||||||
|
- name: add ssh key
|
||||||
|
strategy: free # dont wait for other hosts when executing
|
||||||
|
hosts: all
|
||||||
|
vars_prompt:
|
||||||
|
- name: ssh_key_path
|
||||||
|
prompt: enter the path to the ssh key to add
|
||||||
|
private: false
|
||||||
|
tasks:
|
||||||
|
|
||||||
|
- name: Add ssh key
|
||||||
|
become: true
|
||||||
|
async: 120 # Maximum execution time
|
||||||
|
poll: 05 # polling interval in seconds
|
||||||
|
ansible.posix.authorized_key:
|
||||||
|
user: "{{ ansible_user_id }}"
|
||||||
|
exclusive: false
|
||||||
|
state: present
|
||||||
|
key: "{{ lookup('file', ssh_key_path) }}"
|
||||||
|
|
||||||
@@ -1,13 +1,44 @@
|
|||||||
---
|
---
|
||||||
# https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html#examples
|
# https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html#examples
|
||||||
- name: update apt-cache and upgrade
|
- name: Update ssh key and login permissions
|
||||||
hosts: oracleServer
|
strategy: free # dont wait for other hosts when executing
|
||||||
|
hosts: all
|
||||||
|
vars_prompt:
|
||||||
|
- name: ssh_key_path
|
||||||
|
prompt: enter the path to the ssh key to add
|
||||||
|
private: false
|
||||||
|
- name: ssh_key_comment
|
||||||
|
prompt: enter the comment that should be saved in the authorized_keys file
|
||||||
|
private: false
|
||||||
tasks:
|
tasks:
|
||||||
- name: upgrade packages
|
|
||||||
|
- name: Add ssh key
|
||||||
become: true
|
become: true
|
||||||
|
async: 120 # Maximum execution time
|
||||||
|
poll: 5 # polling interval in seconds
|
||||||
ansible.posix.authorized_key:
|
ansible.posix.authorized_key:
|
||||||
user: "{{ ansible_user_id }}"
|
user: "{{ ansible_user_id }}"
|
||||||
exclusive: true
|
exclusive: false
|
||||||
state: present
|
state: present
|
||||||
key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}"
|
key: "{{ lookup('file', ssh_key_path) }}"
|
||||||
|
comment: "{{ (ssh_key_comment | length > 0) | ternary(ssh_key_comment, omit) }}"
|
||||||
|
|
||||||
|
- name: Update sshd config
|
||||||
|
become: true
|
||||||
|
ansible.builtin.blockinfile:
|
||||||
|
path: /etc/ssh/sshd_config
|
||||||
|
insertbefore: BOF # Beginning of the file
|
||||||
|
marker: "# {mark} ANSIBLE MANAGED BLOCK BY LINUX-ADMIN"
|
||||||
|
block: |
|
||||||
|
PermitRootLogin no
|
||||||
|
PubkeyAuthentication yes
|
||||||
|
AuthorizedKeysFile .ssh/authorized_keys
|
||||||
|
PasswordAuthentication no
|
||||||
|
backup: true
|
||||||
|
validate: /usr/sbin/sshd -T -f %s
|
||||||
|
|
||||||
|
- name: Restart SSHD
|
||||||
|
become: true
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: sshd
|
||||||
|
state: restarted
|
||||||
|
|||||||
Reference in New Issue
Block a user