Ansible.K3sCluster/playbook.yml
djpbessems 50b0f52744
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Initial code for deploying K3s binary (throttled)
2022-04-19 16:36:19 +02:00

85 lines
2.8 KiB
YAML

- name: Provision VM's
hosts: localhost
gather_facts: false
vars_files:
- hypervisor.vcenter.yml
- cluster.k3s.yml
tasks:
- name: Download OVF-template
ansible.builtin.get_url:
url: "https://{{ repo_username }}:{{ repo_password }}@{{ image.ova_url }}"
dest: /scratch/image.ova
- name: Deploy VM's from OVF-template
community.vmware.vmware_deploy_ovf:
hostname: "{{ hv.hostname }}"
username: "{{ hv.username }}"
password: "{{ hv_password }}"
validate_certs: no
datacenter: "{{ hv.datacenter }}"
folder: "{{ hv.folder }}"
cluster: "{{ hv.cluster }}"
name: "{{ cluster.name | upper }}-{{ (item.ip | checksum)[-5:] | upper }}"
datastore: "{{ hv.datastore }}"
disk_provisioning: thin
networks:
"LAN": "{{ hv.network }}"
power_on: yes
ovf: /scratch/image.ova
deployment_option: "{{ image.deployment_option }}"
properties:
guestinfo.hostname: "{{ cluster.name | upper }}-{{ (item.ip | checksum)[-5:] | upper }}"
guestinfo.rootpw: "{{ root_password }}"
guestinfo.rootsshkey: "foo"
guestinfo.ntpserver: "{{ network.ntpserver }}"
guestinfo.ipaddress: "{{ item.ip | ansible.utils.ipaddr('address') }}"
guestinfo.prefixlength: "{{ item.ip | ansible.utils.ipaddr('prefix') }}"
guestinfo.dnsserver: "{{ network.dnsserver }}"
guestinfo.gateway: "{{ network.gateway }}"
delegate_to: localhost
with_items: "{{ servers }}"
register: job_init
async: 300
poll: 0
- name: Poll for completion
ansible.builtin.async_status:
jid: "{{ item.ansible_job_id }}"
with_items: "{{ job_init.results }}"
register: job_poll
retries: 5
delay: 100
until: job_poll.finished
- name: Parse results into dictionary
ansible.builtin.set_fact:
nodes: "{{ nodes | default([]) + [ {'name': item.instance.hw_name, 'ip': item.item.item.ip | ansible.utils.ipaddr('address')} ] }}"
with_items: "{{ job_poll | json_query('results[*]') }}"
no_log: true
- name: Register new VM's in inventory
ansible.builtin.add_host:
name: "{{ item.name }}"
ansible_host: "{{ item.ip }}"
groups: k3s_ha
with_items: "{{ nodes }}"
- name: Provision Kubernetes
hosts: k3s_ha
gather_facts: false
# vars_files:
# - hypervisor.vcenter.yml
# - cluster.k3s.yml
tasks:
- name: Iterate over hosts
block:
- name: Install K3s binary
ansible.builtin.command:
cmd: "curl -sfL https://get.k3s.io | sh -s - server --cluster-init --disable local-storage,traefik --tls-san {{ cluster.virtualip | ansible.utils.ipaddr('address') }}"
environment:
K3S_TOKEN: env.k3s_token | default('', true)
K3S_URL: env.k3s_url | default('', true)
throttle: 1