More content and playbooks

* more readme.md content
* imported basic roles
* commented said basic roles
* trimmed down playbooks to be understandable
* update requirements.txt deps
This commit is contained in:
Thomas Maurice 2023-01-11 11:06:32 +01:00
parent 23b521f4fb
commit 2a067a2fe4
Signed by: thomas
GPG key ID: 1A55753096B00112
22 changed files with 491 additions and 0 deletions

121
roles/base/tasks/main.yml Normal file
View file

@ -0,0 +1,121 @@
---
# welcome to tbe base.yml role. As you can see, this is a collection of
# tasks, which in turn is basically a structure like this one
# name: "user friendly name of your task"
# a_module_name:
# a_module_parameter: value
# another_module_parameter: value2
# this installs packages, here we use the `apt` module
# because we are on a debian-based distribution. If we were
# using something like Fedora for instance, we would have used
# the `dnf` module. Then just pass as arguments the names of
# the packages you want to install just as you would pass them
# to `apt install`.
- name: "Install wanted packages"
apt:
name:
- apt-transport-https
- arptables
- bash-completion
- bridge-utils
- ca-certificates
- cmake
- coreutils
- curl
- dnsutils
- ebtables
- file
- gawk
- git
- glusterfs-client
- glusterfs-server
- gnupg
- htop
- iftop
- ifstat
- iputils-ping
- iptables
- iproute2
- jq
- libsqlite3-dev
- libffi-dev
- libpython3-dev
- libssl-dev
- locales-all
- lsb-release
- lsof
- lvm2
- mdadm
- minicom
- mtr-tiny
- netcat
- net-tools
- ntp
- open-iscsi
- openssl
- p7zip-full
- pwgen
- sqlite3
- strace
- sudo
- sysstat
- telnet
- tcpdump
- tmux
- uuid-runtime
- unzip
- vim-nox
- wget
- wipe
- zip
# state: latest will update the package everytime the
# role is ran against a host
state: latest
# Update the cache before trying to update ?
# You generally want this because it's not updating itself
update_cache: true
# force update it if it's been updated for longer than an hour
cache_valid_time: 3600
register: apt_res
# if running apt fails, retry to do it up to 5 times then give up and cry in the corner
retries: 5
until: apt_res is success
# Same as above, except you *remove* packages instead of installing them
- name: "Remove unanted packages"
apt:
name:
- ntpdate
# note the value of `state` here
state: absent
# This renders a template, the `inventory_hostname` is a variable
# that is golbally available. It will map to the hostname you
# assigned your host in the `inventory` file
- name: "Hard set hostname"
template:
src: hostname.j2
dest: /etc/hostname
owner: root
group: root
# you need to put it in string mode, and you need to
# have a leading `0`, otherwise ansible is going to interpret it weird
# more info https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html#parameter-mode
mode: "0644"
- name: "Setup motd"
template:
src: motd.j2
dest: /etc/motd
owner: root
group: root
mode: "0644"
- name: "Setup hosts"
template:
src: hosts.j2
dest: /etc/hosts
owner: root
group: root
mode: "0644"
# Note that you can also just `copy` files using the copy module:
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html#examples
# And finally you can create files and directories with the `file` module
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html#examples

View file

@ -0,0 +1 @@
{{ inventory_hostname }}

View file

@ -0,0 +1,3 @@
127.0.0.1 localhost
{{ ansible_default_ipv4["address"] }} {{ inventory_hostname }}

View file

@ -0,0 +1,9 @@
This is {{ ansible_fqdn }}
System : {{ ansible_distribution }} {{ ansible_distribution_version }} ({{ ansible_distribution_release }})
Kernel : {{ ansible_kernel }} {{ ansible_kernel_version }}
CPU(s) : {{ ansible_processor_cores }}
RAM : {{ ansible_memory_mb.real.total }}Mb
Architecture : {{ ansible_architecture }}
Address : {{ ansible_default_ipv4.interface }} - {{ ansible_default_ipv4.address }}

60
roles/ntp/files/ntp.conf Normal file
View file

@ -0,0 +1,60 @@
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
# Leap seconds definition provided by tzdata
leapfile /usr/share/zoneinfo/leap-seconds.list
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# Specify one or more NTP servers.
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst
# Use Ubuntu's ntp server as a fallback.
pool ntp.ubuntu.com
# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details. The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.
# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
# Needed for adding pool entries
restrict source notrap nomodify noquery
# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255
# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines. Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

View file

@ -0,0 +1,8 @@
---
# handlers are special tasks that you can invoke when something changes.
# in this example you want to invoke this restart handler when the
# configuration of the service changes for example.
- name: "Restart ntp"
service:
name: ntp
state: restarted

24
roles/ntp/tasks/main.yml Normal file
View file

@ -0,0 +1,24 @@
---
- name: "Install ntp"
apt:
name: ntp
state: present
- name: "Configure ntp"
copy:
src: ntp.conf
dest: /etc/ntp.conf
owner: root
group: root
mode: "644"
# notify is going to invoke the "Restart ntp" handler defined in
# the roles/ntp/handlers/main.yml file. Basically it says that
# you want to restart the ntp service every time the configuratio
# changes
notify: "Restart ntp"
# Here you say that you want the NTP service to be restarted as well
# as enabled on boot.
- name: "ntp service"
service:
name: ntp
state: restarted
enabled: true

View file

@ -0,0 +1,28 @@
---
# Ensures the .ssh directory exists
- name: "creates the .ssh root directory"
file:
path: "/root/.ssh"
state: directory
owner: root
group: root
mode: 0700
- name: "Install root SSH keys"
template:
src: authorized_keys.j2
dest: /root/.ssh/authorized_keys
owner: root
group: root
mode: 0600
# Delete users you don't need
# respectively you can also *add* users
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html#ansible-collections-ansible-builtin-user-module
- name: "Delete usual cloud users user"
user:
name: "{{ item }}"
state: absent
remove: true
with_items:
- pi
- admin
- ubuntu

View file

@ -0,0 +1,4 @@
{% for key in root_user.default_root_keys %}
# {{ key.name }}
{{ key.key }}
{% endfor %}

51
roles/vim/files/vimrc Normal file
View file

@ -0,0 +1,51 @@
set nocompatible
filetype on
filetype plugin indent on
syntax on
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set smarttab
set lazyredraw
set showmatch
set incsearch
set hlsearch
set number
set ruler
set autoindent
set smartindent
set wildmenu
set laststatus=2
set cursorline
set showmode
set backspace=indent,eol,start
set mouse=a
set background=dark
set foldenable
set foldlevelstart=10
set foldmethod=indent
nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
set showmode
let mapleader=","
nnoremap <leader><space> :nohlsearch<CR>
nnoremap <space> za
map <Leader><Right> 10<C-w><<CR>
map <Leader><Down> 10<C-w>-<CR>
map <Leader><Up> 10<C-w>+<CR>
map <Leader><Left> 10<C-w>><CR>
map <Leader>= 10<C-w>=<CR>
map <Leader>s :%s/\s\+$//<CR>
nnoremap tt :tabnew<CR>
nnoremap to :tabonly<CR>
nnoremap tc :tabclose<CR>
nnoremap tn :tabnext<CR>
nnoremap tp :tabprevious<CR>
nnoremap vs :vsplit

12
roles/vim/tasks/main.yml Normal file
View file

@ -0,0 +1,12 @@
---
- name: Install vim
apt:
name: vim-nox
state: latest
# use the `copy` module to copy files to the remote host
- name: Configure vim
copy:
src: vimrc
dest: /etc/vim/vimrc
owner: root
group: root