Commit c50bb4a9 authored by rlacko's avatar rlacko 💬
Browse files

Base config for kubernetes vm

parent a4fbea3c
Role Name
=========
# Role Name
A brief description of the role goes here.
Base role for every Kubernetes VM.
It will install base packages, configures ssh and
disables floppy, multipathd for vmware.
Requirements
------------
## License
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
MIT
Role Variables
--------------
## Author Information
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
KSZK
/home/rlacko/codes/kszk/k8s/cluster-setup/roles/base-ansible-role
\ No newline at end of file
---
# defaults file for myrole
timezone: Europe/Budapest
na: "https://git.sch.bme.hu/kszk/sysadmin/kubernetes/base-ansible-role"
hostname: "{{ inventory_hostname }}"
ssh:
port: 10022
pubkeyAuthentication: "yes"
passwordAuthentication: "no"
permitRootLogin: "without-password"
allow:
#users: root, ubuntu
# groups: root
# passwordLoginFrom:
# custom:
# enabled: False
# ipList: "192.168.42.0/24"
users:
#- name: kszk
# comment: "kszk@sch.bme.hu" # optional
# sudo: yes
# passwordless_sudo: yes
# # https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html#examples
# keys_url: https://git.sch.bme.hu/xy.keys
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
author: kszk
description: Base role for Kubernetes VMs
company: KSZK
license: MIT
platforms:
- name: Ubuntu
versions:
- all
min_ansible_version: 2.9
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
dependencies:
- yatesr.timezone
collections:
- community.general
- community.crypto
- ansible.posix
---
- name: Disable floppy module
template:
src: etc/modprobe.d/blacklist-floppy.conf.j2
dest: /etc/modprobe.d/blacklist-floppy.conf
mode: 0644
register: blacklist_floppy
- name: Unload floppy kernel module
modprobe:
name: floppy
state: absent
when: blacklist_floppy.changed
- name: Update initramfs after floppy is disabled
command: update-initramfs -u
when: blacklist_floppy.changed
---
# tasks file for myrole
# Dependent roles will be installed first
- name: Set hostname
when: hostname is defined
hostname:
name: "{{ hostname }}"
tags: [hostname]
- name: Upgrade packages
import_tasks: update.yml
tags: [update]
- name: Setup admin users
include_tasks: setup_user.yml
loop: "{{ users }}"
loop_control:
loop_var: user
- name: Install basic packages
import_tasks: packages.yml
tags: [packages]
- name: Setup Message of the day (MOTD)
import_tasks: "motd.yml"
tags: [motd]
- name: Setup SSH
import_tasks: "ssh.yml"
tags: [ssh]
- name: Disable floppy
include_tasks: floppy.yaml
- name: Fix multipath UUID VMWare errors
include_tasks: multipath.yaml
---
- name: Remove parts of factory banner
file:
path: "{{ item }}"
state: absent
with_items:
- /etc/update-motd.d/10-help-text
- /etc/update-motd.d/50-motd-news
- name: Place motd file.
template:
src: etc/update-motd.d/motd.sh
dest: /etc/update-motd.d/40-kszk-banner
mode: 0755
---
- name: Blacklist multipath in VMWare disks
template:
src: etc/multipath.conf.j2
dest: /etc/multipath.conf
mode: 0644
register: blacklist_vmware_multipath
- name: Ensure multipath is restarted.
service:
name: multipath-tools
state: restarted
when: blacklist_vmware_multipath.changed
---
- name: Install open-vm-tools (if VM)
package:
name: open-vm-tools
state: present
when: ansible_virtualization_type == "VMware"
- name: Install basic packages
package:
state: present
name:
# Debug tools
- sudo
- tmux
- htop
- dnsutils
- net-tools
- psmisc
- strace
- tcpdump
- xxd
# Editors
- nano
- neovim
# Admin helpers
- rsync
- tree
- molly-guard
# Dependencies for scripting
- python3
- unzip
- curl
- wget
- jq
---
- debug:
msg: "{{ user }}"
- name: "Create group for user"
group:
name: "{{ user.name }}"
- name: "Create user"
user:
name: "{{ user.name }}"
comment: "{{ user.comment | default('') }}"
group: "{{ user.name }}"
shell: "/bin/{{ user.shell | default('bash') }}"
- name: "SUDO"
user:
name: "{{ user.name }}"
append: true
groups:
- sudo
when: user.sudo
- set_fact:
sudoer_file: "/etc/sudoers.d/{{ user.name }}"
- name: sudoers file for the user
file:
path: "{{ sudoer_file }}"
state: touch
mode: "0600"
owner: root
group: root
- name: Insert sudoer file content
copy:
dest: "{{ sudoer_file }}"
content: "{{ user.name }} ALL=(ALL) NOPASSWD:ALL"
when: user.passwordless_sudo
- name: "Set password to be expired"
command: passwd --delete '{{ user.name }}'
when: not user.passwordless_sudo
- name: Set authorized keys
ansible.posix.authorized_key:
user: "{{ user.name }}"
state: present
key: "{{ user.keys_url }}"
manage_dir: yes
exclusive: yes
---
- name: Place sshd configuration file.
template:
src: etc/ssh/sshd_config
dest: /etc/ssh/sshd_config
mode: 0600
register: sshd_config
# disable the ssh.socket, otherwise it will collide with ssh.service
- name: Ensure ssh socket is disabled
service:
name: ssh.socket
enabled: no
- name: Ensure sshd is started and enabled to start at boot.
service:
name: sshd
state: restarted
enabled: yes
when: sshd_config.changed
---
- name: Update and upgrade apt packages
become: yes
apt:
upgrade: 'yes'
update_cache: yes
cache_valid_time: 86400 #One day
#
# !!!
# {{ ansible_managed }}
# !!!
blacklist floppy
#
# !!!
# {{ ansible_managed }}
# !!!
defaults {
user_friendly_names yes
}
blacklist {
device {
vendor "VMware"
product "Virtual disk"
}
}
#
# !!!
# {{ ansible_managed }}
# !!!
Protocol 2
Port {{ ssh.port }}
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com
PermitRootLogin {{ ssh.permitRootLogin }}
PubkeyAuthentication {{ ssh.pubkeyAuthentication }}
PasswordAuthentication {{ ssh.passwordAuthentication }}
MaxAuthTries 6
ChallengeResponseAuthentication no
KerberosAuthentication no
GSSAPIAuthentication no
UsePAM yes
AllowAgentForwarding yes
X11Forwarding yes
PrintMotd no
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
{% if ssh.allow.users is defined %}
AllowUsers {{ ssh.allow.users }}
{% endif %}
{% if ssh.allow.groups is defined %}
AllowGroups {{ ssh.allow.groups }}
{% endif %}
#!/bin/sh
# !!!
# {{ ansible_managed }}
# !!!
# source: http://patorjk.com/software/taag/#p=display&f=Standard&t=KSZK%20server
cat <<EOF
_ ______ ______ __
| |/ / ___|__ / |/ / ___ ___ _ ____ _____ _ __
| ' /\___ \ / /| ' / / __|/ _ \ '__\ \ / / _ \ '__|
| . \ ___) / /_| . \ \__ \ __/ | \ V / __/ |
|_|\_\____/____|_|\_\ |___/\___|_| \_/ \___|_|
EOF
echo "! ! !"
echo "! Deployed with Ansible on {{ template_run_date.strftime('%Y-%m-%d %H:%M') }}."
echo "! Playbook: {{ motd_playbook_url }}"
echo "! ! !"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment