Merge pull request #90 from jdratlif/main

A few updates for the RKE2 ansible plays
This commit is contained in:
James 2024-09-25 15:49:04 +01:00 committed by GitHub
commit 8aed1489df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 134 additions and 17 deletions

View File

@ -0,0 +1,26 @@
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bookworm
# enable git bash completion
RUN ln -s /usr/share/bash-completion/completions/git /usr/share/bash-completion/bash_completion
# install sshpass for ansible SSH password auth and vim just in case
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y sshpass vim
RUN apt-get clean
# install ansible and ansible-lint
RUN python3 -m pip install ansible-core~=2.16.6 ansible-lint~=24.2.3
# create /workspace directory
WORKDIR /workspace
RUN chown -R vscode:vscode /workspace
# run commands as non-root user
USER vscode
# make prompt multiline cause it's too long by default
RUN sed -i -E -e '/PS1="\$/c\ PS1="${userpart} ${lightblue}\\w ${gitbranch}${removecolor}\\n\\$ "' ~/.bashrc
# install collection requirements
COPY collections/requirements.yaml .
RUN ansible-galaxy collection install -r requirements.yaml

View File

@ -0,0 +1,54 @@
{
"name": "ansible-rke2",
"build": {
"dockerfile": "Dockerfile",
"context": "../../Ansible/Playbooks/RKE2"
},
"mounts": ["source=${env:HOME}/.ssh,target=/home/vscode/.ssh,type=bind"],
"customizations": {
"vscode": {
"extensions": [
"bierner.markdown-preview-github-styles",
"DavidAnson.vscode-markdownlint",
"dhoeric.ansible-vault",
"eamodio.gitlens",
"esbenp.prettier-vscode",
"mhutchie.git-graph",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.isort",
"oderwat.indent-rainbow",
"redhat.ansible",
"samuelcolvin.jinjahtml",
"tamasfe.even-better-toml",
"yzhang.markdown-all-in-one"
],
"settings": {
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"ansible.python.interpreterPath": "/usr/local/bin/python",
"ansibleVault.executable": "/home/vscode/venv/bin/ansible-vault",
"editor.formatOnSave": true,
"files.associations": {
"*.yaml": "ansible"
},
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"python.defaultInterpreterPath": "/usr/local/bin/python"
}
}
}
}

View File

@ -0,0 +1,3 @@
[defaults]
inventory = inventory/hosts.ini
host_key_checking = false

View File

@ -1,18 +1,18 @@
---
os: "linux"
arch: "amd64"
kube_vip_version: "v0.8.0"
vip_interface: eth0
vip: 192.168.3.50
metallb_version: v0.13.12
lb_range: 192.168.3.80-192.168.3.90
lb_pool_name: first-pool
rke2_version: "v1.29.4+rke2r1"
rke2_install_dir: "/usr/local/bin"
rke2_binary_url: "https://github.com/rancher/rke2/releases/download/{{ rke2_version }}/rke2.linux-amd64"
ansible_user: ubuntu
ansible_become: true
ansible_become_method: sudo
################################################################################
# options to change default values
# kube_vip_version: "v0.8.0"
# vip_interface: "eth0"
# rke2_version: "v1.29.4+rke2r1"
# rke2_install_dir: "/usr/local/bin"

View File

@ -9,3 +9,12 @@ server3 ansible_host=192.168.3.23
[agents]
agent1 ansible_host=192.168.3.24
agent2 ansible_host=192.168.3.25
[rke2]
[rke2:children]
servers
agents
[rke2:vars]
ansible_user=ansible

View File

@ -0,0 +1,3 @@
---
kube_vip_version: v0.8.0
vip_interface: eth0

View File

@ -0,0 +1,22 @@
---
argument_specs:
main:
short_description: Install kube-vip manifest
description: Install kube-vip manifest
author:
- James Turland <james@turland.uk>
options:
kube_vip_version:
type: str
required: false
default: v0.8.0
description: Version of kube-vip to install
vip_interface:
type: str
required: false
default: eth0
description: Interface to bind kube-vip
vip:
type: str
required: true
description: The virtual IP to use with kube-vip

View File

@ -3,7 +3,7 @@
ansible.builtin.file:
path: "/var/lib/rancher/rke2/server/manifests"
state: directory
mode: '0644'
mode: "0755"
when: inventory_hostname in groups['servers']
# Copy kube-vip to server 1 manifest folder for auto deployment at bootstrap
@ -13,5 +13,5 @@
dest: /var/lib/rancher/rke2/server/manifests/kube-vip.yaml
owner: root
group: root
mode: '0644'
mode: "0644"
when: inventory_hostname == groups['servers'][0]

View File

@ -0,0 +1,3 @@
---
rke2_install_dir: "/usr/local/bin"
rke2_version: "v1.29.4+rke2r1"

View File

@ -0,0 +1,2 @@
---
rke2_binary_url: "https://github.com/rancher/rke2/releases/download/{{ rke2_version }}/rke2.{{ os }}-{{ arch }}"

View File

@ -13,16 +13,11 @@
# bootstraps first server and copies configs for others/agents
- name: Prepare all nodes
hosts: servers,agents
gather_facts: true # enables us to gather lots of useful variables: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/setup_module.html
hosts: rke2
gather_facts: false # fact gathering is slow and not needed for any of our tasks
become: true
roles:
- prepare-nodes
# creates directories for download and then downloads RKE2 and changes permissions
- name: Download RKE2
hosts: servers,agents
gather_facts: true
roles:
- rke2-download
# Creates RKE2 bootstrap manifests folder and copies kube-vip template over (configured with variables)