initial checkin
rework of lxdhost and setup-host playbooks
This commit is contained in:
commit
1a10903da8
|
@ -0,0 +1,21 @@
|
|||
# deploy-host playbook
|
||||
|
||||
## Introduction
|
||||
|
||||
Playbook to deploy an LXD Container or VM as a new network host.
|
||||
|
||||
This playbook will first deploy a new LXD Container or VM. It will then use
|
||||
the lxd connection plugin to first do an initial network configuration on
|
||||
the host, and will then make sure openssh-server is installed and that the
|
||||
root user has a set of management ssh keys in its 'authorized_keys' file.
|
||||
|
||||
It will run through a number of roles to do package and user configuration,
|
||||
before finishing up with custom configurations for the specific target host.
|
||||
|
||||
This playbook can be run using the following command line;
|
||||
|
||||
ansible-playbook -i <inventory file | IP,> deploy-host.yml
|
||||
|
||||
ie,
|
||||
ansible-playbook -i 192.168.1.123, deploy-host.yml
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
---
|
||||
#####################################################################
|
||||
#
|
||||
# Playbook to deploy an LXD container as a new network host
|
||||
#
|
||||
# deploy_host.yml
|
||||
#
|
||||
# ansible-playbook -l <guest-host> -i lxdhost_inventory.yml deploy_host.yml
|
||||
#
|
||||
# This playbook will first deploy a new LXD container. It will then use
|
||||
# the lxd connection plugin to first do an initial network configuration
|
||||
# on the container, and will then make sure openssh-server is installed
|
||||
# and that the root user has a set of management ssh keys in its
|
||||
# 'authorized_keys' file.
|
||||
#
|
||||
# It will run through a number of roles to do package and user
|
||||
# configuration, before finishing up with custom configurations for
|
||||
# the specific target host.
|
||||
#
|
||||
#####################################################################
|
||||
|
||||
#####################################################################
|
||||
# Start off with local connection to perform the initial container
|
||||
# deployment. After that it will use a mix of local and lxd
|
||||
# connections to prepare the container for management via ssh.
|
||||
|
||||
- hosts: all
|
||||
connection: local
|
||||
user: root
|
||||
|
||||
vars:
|
||||
guest_name: "{{ hostvars[inventory_hostname].inventory_hostname }}"
|
||||
guest_ip: "{{ hostvars[inventory_hostname].ansible_host }}"
|
||||
image_name: "{{ hostvars[inventory_hostname].image_name }}"
|
||||
image_vers: "{{ hostvars[inventory_hostname].image_vers }}"
|
||||
image_location: "{{ hostvars[inventory_hostname].image_location }}"
|
||||
deploy_host: "{{ hostvars[inventory_hostname].deploy_host }}"
|
||||
remote_name: "{{ hostvars[inventory_hostname].remote_name }}"
|
||||
guest_distro: "{{ hostvars[inventory_hostname].image_name }}"
|
||||
cpu_num: "{{ hostvars[inventory_hostname].cpu }}"
|
||||
mem_size: "{{ hostvars[inventory_hostname].mem }}"
|
||||
root_size: "{{ hostvars[inventory_hostname].root }}"
|
||||
|
||||
roles:
|
||||
- role: lxc_deploy
|
||||
- role: lxdhost
|
||||
|
||||
#####################################################################
|
||||
# run the setup-host.yml playbook for host configuration
|
||||
|
||||
- hosts: all
|
||||
gather_facts: true
|
||||
user: root
|
||||
|
||||
- name: include the setup-host.yml playbook
|
||||
import_playbook: setup-host.yml
|
||||
|
||||
# EOF
|
|
@ -0,0 +1,151 @@
|
|||
---
|
||||
#####################################################################
|
||||
# example inventory file for deploy-host.yml
|
||||
|
||||
all:
|
||||
hosts:
|
||||
node1:
|
||||
#######################################
|
||||
# Host inventory definition
|
||||
# node1
|
||||
#######################################
|
||||
# host network configuration
|
||||
ansible_host: 192.168.20.231
|
||||
ip_gw: 192.168.20.1
|
||||
ip_ns1: 192.168.20.21
|
||||
ip_ns2: 192.168.20.22
|
||||
#######################################
|
||||
# VM/Container LXD configuration
|
||||
# LXD Container or VM
|
||||
host_type: Container
|
||||
# LXD profile to apply
|
||||
profile: bridged
|
||||
# LXD image selection
|
||||
image_name: "ubuntu"
|
||||
image_vers: "22.04"
|
||||
image_location: "images"
|
||||
# where to deploy container
|
||||
remote_name: starbug
|
||||
#######################################
|
||||
# Host virtual hardware configuration
|
||||
# CPU cores, Memory, Root disk size
|
||||
cpu: 2
|
||||
mem: 4
|
||||
root: 50
|
||||
#######################################
|
||||
# Ansible roles to apply to host
|
||||
# - uncomment to select
|
||||
# - create_user includes create_user, sudoers, vim_setup, bash_mods and gitconfig roles
|
||||
# - use "nil" for no ansible configuration management
|
||||
host_config:
|
||||
- nil
|
||||
# - base_pkgs
|
||||
# - create_user
|
||||
# - du_backups
|
||||
# - monitorix
|
||||
# - nagios_agent
|
||||
# - docker
|
||||
# - k3s
|
||||
#######################################
|
||||
# user definition for "create_user" role
|
||||
user: rmorrow
|
||||
pw: resetthispasswd
|
||||
home: /home/rmorrow
|
||||
|
||||
node2:
|
||||
#######################################
|
||||
# Host inventory definition
|
||||
# node2
|
||||
#######################################
|
||||
# host network configuration
|
||||
ansible_host: 192.168.20.232
|
||||
ip_gw: 192.168.20.1
|
||||
ip_ns1: 192.168.20.21
|
||||
ip_ns2: 192.168.20.22
|
||||
#######################################
|
||||
# VM/Container LXD configuration
|
||||
# LXD Container or VM
|
||||
host_type: Container
|
||||
# LXD profile to apply
|
||||
profile: bridged
|
||||
# LXD image selection
|
||||
image_name: "ubuntu"
|
||||
image_vers: "22.04"
|
||||
image_location: "images"
|
||||
# where to deploy container
|
||||
remote_name: starbug
|
||||
#######################################
|
||||
# Host virtual hardware configuration
|
||||
# CPU cores, Memory, Root disk size
|
||||
cpu: 2
|
||||
mem: 4
|
||||
root: 50
|
||||
#######################################
|
||||
# Ansible roles to apply to host
|
||||
# - uncomment to select
|
||||
# - create_user includes create_user, sudoers, vim_setup, bash_mods and gitconfig roles
|
||||
# - use "nil" for no ansible configuration management
|
||||
host_config:
|
||||
- nil
|
||||
# - base_pkgs
|
||||
# - create_user
|
||||
# - du_backups
|
||||
# - monitorix
|
||||
# - nagios_agent
|
||||
# - docker
|
||||
# - k3s
|
||||
#######################################
|
||||
# user definition for "create_user" role
|
||||
user: rmorrow
|
||||
pw: resetthispasswd
|
||||
home: /home/rmorrow
|
||||
|
||||
node3:
|
||||
#######################################
|
||||
# Host inventory definition
|
||||
# node3
|
||||
#######################################
|
||||
# host network configuration
|
||||
ansible_host: 192.168.20.233
|
||||
ip_gw: 192.168.20.1
|
||||
ip_ns1: 192.168.20.21
|
||||
ip_ns2: 192.168.20.22
|
||||
#######################################
|
||||
# VM/Container LXD configuration
|
||||
# LXD Container or VM
|
||||
host_type: Container
|
||||
# LXD profile to apply
|
||||
profile: bridged
|
||||
# LXD image selection
|
||||
image_name: "ubuntu"
|
||||
image_vers: "22.04"
|
||||
image_location: "images"
|
||||
# where to deploy container
|
||||
remote_name: starbug
|
||||
#######################################
|
||||
# Host virtual hardware configuration
|
||||
# CPU cores, Memory, Root disk size
|
||||
cpu: 2
|
||||
mem: 4
|
||||
root: 50
|
||||
#######################################
|
||||
# Ansible roles to apply to host
|
||||
# - uncomment to select
|
||||
# - create_user includes create_user, sudoers, vim_setup, bash_mods and gitconfig roles
|
||||
# - use "nil" for no ansible configuration management
|
||||
host_config:
|
||||
- nil
|
||||
# - base_pkgs
|
||||
# - create_user
|
||||
# - du_backups
|
||||
# - monitorix
|
||||
# - nagios_agent
|
||||
# - docker
|
||||
# - k3s
|
||||
#######################################
|
||||
# user definition for "create_user" role
|
||||
user: rmorrow
|
||||
pw: resetthispasswd
|
||||
home: /home/rmorrow
|
||||
|
||||
# EOF
|
|
@ -0,0 +1,96 @@
|
|||
---
|
||||
###########################################################################
|
||||
#
|
||||
# This is a playbook to deploy a default configurations to a LAN host.
|
||||
#
|
||||
###########################################################################
|
||||
#
|
||||
# This playbook depends on the 'host_config' list variable in an inventory
|
||||
# definition file
|
||||
#
|
||||
########################################
|
||||
#
|
||||
# This playbook can be run using the following command line;
|
||||
#
|
||||
# ansible-playbook -i <inventory file | IP,> setup_host.yml
|
||||
#
|
||||
# ie,
|
||||
# ansible-playbook -i 192.168.1.123, setup_host.yml
|
||||
# or
|
||||
# ansible-playbook -l (host) -i inventory/delfax.yml setup_host.yml
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
- hosts: all
|
||||
gather_facts: true
|
||||
user: root
|
||||
|
||||
vars:
|
||||
username: "{{ hostvars[inventory_hostname].user }}"
|
||||
sudoers_user: "{{ hostvars[inventory_hostname].user }}"
|
||||
userpw: "{{ hostvars[inventory_hostname].pw }}"
|
||||
homedir: "{{ hostvars[inventory_hostname].home }}"
|
||||
host_config: "{{ hostvars[inventory_hostname].host_config }}"
|
||||
guest_ip: "{{ hostvars[inventory_hostname].ansible_host }}"
|
||||
|
||||
roles:
|
||||
|
||||
#######################################################
|
||||
# roles applied to all guests
|
||||
- role: update_cache
|
||||
- role: upgrade_pkgs
|
||||
- role: pfetch
|
||||
|
||||
#######################################################
|
||||
- role: base_pkgs
|
||||
when: '"base_pkgs" in host_config'
|
||||
|
||||
#######################################################
|
||||
- role: create_user
|
||||
when: '"create_user" in host_config'
|
||||
- role: sudoers
|
||||
when: '"create_user" in host_config'
|
||||
- role: vim_setup
|
||||
when: '"create_user" in host_config'
|
||||
- role: bash_mods
|
||||
when: '"create_user" in host_config'
|
||||
- role: gitconfig
|
||||
when: '"create_user" in host_config'
|
||||
|
||||
#######################################################
|
||||
- role: du_backups
|
||||
when: '"du_backups" in host_config'
|
||||
|
||||
#######################################################
|
||||
- role: monitorix
|
||||
vars:
|
||||
# set variable to same value as in monitorix.yml playbook
|
||||
monitorix_pkg: "monitorix_3.15.0-izzy1_all.deb"
|
||||
when: '"monitorix" in host_config'
|
||||
|
||||
#######################################################
|
||||
- role: nagios_agent
|
||||
vars:
|
||||
agent_ip: "{{ guest_ip }}"
|
||||
when: '"nagios_agent" in host_config'
|
||||
|
||||
#######################################################
|
||||
- role: docker
|
||||
vars:
|
||||
# set variable to same value as in docker.yml playbook
|
||||
docker_compose_version: "v2.14.2"
|
||||
when: '"docker" in host_config'
|
||||
|
||||
#######################################################
|
||||
- role: k3s
|
||||
vars:
|
||||
# Calculate the number of target hosts
|
||||
numhosts: "{{ ansible_play_hosts | length }}"
|
||||
# first inventory host will be master node
|
||||
master_host: "{{ ansible_play_hosts[0] }}"
|
||||
master_ip: "{{ hostvars[master_host].ansible_host }}"
|
||||
# change k3s_user to create a non-root admin user
|
||||
k3s_user: root
|
||||
when: '"k3s" in host_config'
|
||||
|
||||
# EOF
|
Loading…
Reference in New Issue