An Ansible Role that initial setup a server/vm
The available variables are listed below (sorted temporally according to use), for all references see defaults/main.yml
Boolean true or false for update all software during profilinga (def. true)
software_update: true
List of packages to install with default to:
packages:
- wget
- openssh-server
Boolean true or false to auto security updates packages using (def. no):
- unattended-upgrades for Ubuntu OS;
- dnf-automatic for RedHat OS version greter equal then 8;
- yum-cron for RedHat OS version less than 8
auto_upgrade: no
Boolean true or false for install screen or tmux package (def. true). Install screen on all OS except for RedHat OS version greater equal then 8. When screen is installed there will also be the .screenrc file under /root
screen_or_tmux: true
The hostname to set (def. no hostname set)
hostname: myhostname
The Timezone to set in this server (def. Europe/Rome)
for list of timezone see command: timedatectl list-timezones
timezone: Europe/Rome
A locale's list to enable, with default to:
for list of locales see command: localectl list-locales
locales:
- en_US.UTF-8
- it_IT.UTF-8
The default locale (def. en_US.UTF-8)
locale_def: en_US.UTF-8
Add or remove ssh authorized keys to .ssh/authorized_keys file (def. [])
Each element of the array/list is a dictionary of key/value where:
- re: its value is the regular expression to look for in every line in .ssh/authorized_keys
- key: its value is the ssh key to add
- state: its value, if exists must be
present
orabsent
withpresent
as default for update or insert the ssh key. Ifabsent
the ssh key will be removed
See example below
ssh_keys: []
Boolean to disable or enable ipv6 (def. true, ipv6 disabled)
disable_ipv6 = true
Dictionary of key/value to use with sysctl command (def. is empty dict). The key/value will be saved in /etc/sysctl.d/999-sysctl-server_initial_setup.conf
Some values can be changed by other software such as ufw firewall on startup:
- see /etc/ufw/sysctl.conf on Ubuntu system
sysctls: {}
Boolean true or false to enable or not a firewall (def. true). On Ubuntu/Debian use ufw firewall while on RedHat system use firewalld firewall
firewall: true
Configure firewall ufw only for Ubuntu/Debian OS. You can add profiles with profile_enable: or rules with rules:
Default value to:
firewall: true
ufw:
profile_enable:
- OpenSSH
Configure firewall firewalld for ReadHat OS (RedHat, Centos, RockyLinux). You can add service with service_enable:
Default value to:
firewall: true
firewalld:
service_enable:
- ssh
Boolean to force use iptables / ip6tables instead of ufw or firewalld (def. false)
force_iptables: false
Path where save the templates (iptables_main_rules.j2 and ip6tables_main_rules.j2) shell for iptables_rules and ip6tables_rules (def. /root/iptables_rules)
iptables_rules_path: "/root/iptables_rules"
It's an array of iptables rules. Rules can be inserted with or without leading iptables. iptables_rules needs option force_iptables: true (def. [])
iptables_rules: []
It's an array of ip6tables rules. Rules can be inserted with or without leading ip6tables. ip6tables_rules needs option force_iptables: true (def. [])
ip6tables_rules: []
No dependencies in particolar
Install with:
ansible-galaxy install eniocarboni.server_initial_setup
---
- hosts: all
become: true
roles:
- eniocarboni.server_initial_setup
---
- hosts: all
become: true
roles:
- role: eniocarboni.server_initial_setup
hostname: "privhostname"
timezone: "America/New_York"
packages:
- wget
- virtualbox
- vagrant
disable_ipv6: false
---
- hosts: all
become: true
roles:
- role: eniocarboni.server_initial_setup
hostname: "privhostname"
timezone: "Europe/Rome"
packages:
- wget
sysctls:
vm.swappiness: 10
net.ipv4.conf.all.accept_source_route: 0
disable_ipv6: false
force_iptables: true
iptables_rules_path: "/root/iptables_rules"
iptables_rules:
- "-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT"
- "-A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT"
- "-A INPUT -p udp --syn -m state --state NEW --dport 53 -j ACCEPT"
- "-A INPUT -p udp -m state --state NEW --dport 53 -j ACCEPT"
- "-A INPUT -p tcp --dport 22 -j ACCEPT"
- "-P INPUT DROP"
- "-P OUTPUT ACCEPT"
ip6tables_rules: []
---
- hosts: all
become: true
roles:
- role: eniocarboni.server_initial_setup
ssh_keys:
- re: "eniocarboni_rsa_2048bit"
key: "ssh-rsa AAAA...hgl== eniocarboni_rsa_2048bit"
- re: "oldkeys"
state: absent
GNU General Public License v3.0, see LICENSE file
This role was created in 2022 by Enio Carboni