This script is intended to be used with the Telmate terraform provider for Proxmox
- Telmate terraform provider installed via
terraform init
- must use
tags = "server"
ortags = "worker"
when defining server and worker VM's in the terraform provider - have a successfull
terraform apply
that created theterraform.tfstate
file - Ansible installed
- jq installed
- macOS -
brew install jq ansible
- Debian/Old Ubuntu -
apt install jq ansible
- New Ubuntu >= 20.04 -
snap install jq ansible
- Arch -
pacman -S jq ansible
Shown here is an application of the example terraform scripts in examples/3.k8s of my Proxmox module that uses the Telmate Proxmox provider. Refer to that example.
After running your terraform apply
, it will create the terraform.tfstate
file:
$ ls -l
total 40
-rw-r--r-- 1 brian brian 1217 Dec 14 03:34 main.tf
-rw-r--r-- 1 brian brian 18378 Dec 14 03:31 terraform.tfstate
-rw-r--r-- 1 brian brian 5655 Dec 14 03:30 terraform.tfstate.backup
You then run this script telmate_proxmox_tf_ansible.sh
in the same directory as your terraform.tfstate
file.
It will create the inventory file hosts.txt
suitable for use with Ansible. It can also optionally download the public SSH host keys from each new VM and put the public host keys into the user's $HOME/.ssh/known_hosts
file. This is needed for SSH to work with Ansible.
$ telmate_proxmox_tf_ansible.sh
Created Ansible inventory file 'hosts.txt'
Do you want to import the public SSH host keys
for all hosts in the inventory?
Yes or No? (default: Yes) >>> yes
Done!
Looking at the file hosts.txt
you will see that it is compatible with the k3s installer, making it very easy to simply run the official k3s playbook with this hosts.txt
file:
$ cat hosts.txt
# This hosts file is compatible with the official k3s playbook at
# https://github.com/k3s-io/k3s-ansible
[all:children]
master
node
[k3s_cluster:children]
master
node
[master]
192.168.0.75 # k8s-server-1
[node]
192.168.0.88 # k8s-worker-1
192.168.0.99 # k8s-worker-2
192.168.0.92 # k8s-worker-3
Now try to ping each host using this hosts.txt
file and the Ansible ping
module:
$ ansible -i hosts.txt all -u ubuntu -m ping -v
Using /home/brian/.ansible.cfg as config file
192.168.0.75 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
192.168.0.88 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
192.168.0.99 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
192.168.0.92 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}