diff options
Diffstat (limited to 'tofu/ansible')
| -rw-r--r-- | tofu/ansible/hosts | 1 | ||||
| -rwxr-xr-x | tofu/ansible/local_script | 8 | ||||
| -rw-r--r-- | tofu/ansible/main.tf | 37 |
3 files changed, 46 insertions, 0 deletions
diff --git a/tofu/ansible/hosts b/tofu/ansible/hosts new file mode 100644 index 0000000..e5bdaa1 --- /dev/null +++ b/tofu/ansible/hosts @@ -0,0 +1 @@ +webserver1 ansible_host=192.168.122.213 ansible_user=ansible ansible_become=true diff --git a/tofu/ansible/local_script b/tofu/ansible/local_script new file mode 100755 index 0000000..14b6121 --- /dev/null +++ b/tofu/ansible/local_script @@ -0,0 +1,8 @@ +#!/bin/bash +ssh-keygen -f ~/.ssh/known_hosts -R $1 +# on attend que cloud-init ait fini d'installer le serveur SSH +while ! ssh-keyscan -H $1 >> ~/.ssh/known_hosts; do + sleep 1 +done +ansible -u ansible --become -i "$1," -m ping all +echo $2 ansible_host=$1 ansible_user=ansible ansible_become=true >> hosts diff --git a/tofu/ansible/main.tf b/tofu/ansible/main.tf new file mode 100644 index 0000000..0bbc448 --- /dev/null +++ b/tofu/ansible/main.tf @@ -0,0 +1,37 @@ +terraform { + required_providers { + incus = { + source = "lxc/incus" + version = "0.3.1" + } + } +} + +provider "incus" { + # Configuration options +} + +resource "incus_instance" "debian" { + name = "webserver1" + project = "lab" + image = "images:debian/12/cloud" + wait_for { + type = "ipv4" + } + provisioner "local-exec" { + command = "./local_script ${self.ipv4_address} ${self.name}" + } +} + +resource "incus_instance" "rocky" { + name = "webserver2" + project = "lab" + image = "images:rockylinux/9/cloud" + wait_for { + type = "ipv4" + } + provisioner "local-exec" { + command = "./local_script ${self.ipv4_address} ${self.name}" + } +} + |
