![Provedor Ansible para suporte a funções do Terraform](https://rvso.com/image/788900/Provedor%20Ansible%20para%20suporte%20a%20fun%C3%A7%C3%B5es%20do%20Terraform.png)
Tenho um manual do Ansible com funções que desejo executar no Terraform.
site.yaml
---
- hosts: cluster
gather_facts: yes
become: yes
roles:
- role: prereq
roles/prereq/tasks/main.yml
contém as tarefas.
Com Ansible, primeiro crio o inventário:
inventory/hosts
[bastion]
192.168.2.1
[node]
192.168.2.2
192.168.2.3
[cluster:children]
node
[cluster:vars]
ansible_ssh_common_args='-o ProxyCommand="ssh -W %h:%p -q [email protected]"'
Então eu lanço ansible-playbook -i inventory/hosts site.yml
.
Quero reproduzir isso no Terraform sem criar manualmente o arquivo de inventário/hosts. Eu fiz o seguinte:
terraform {
required_providers {
ansible = {
source = "ansible/ansible"
version = "~> 1.1.0"
}
}
resource "ansible_group" "bastion" {
name = "bastion"
}
resource "ansible_group" "nodes" {
name = "node"
}
resource "ansible_group" "cluster" {
name = "cluster"
children = [
ansible_group.nodes.name
]
variables = {
ansible_ssh_common_args = "-o ProxyCommand='...'"
}
}
# NOTE bastion and then nodes come from a remote state.
resource "ansible_host" "bastion" {
name = bastion.ip
groups = [ansible_group.bastion.name]
}
resource "ansible_host" "nodes" {
for_each = { for key, val in nodes : key => val }
name = each.value.ip
groups = [ansible_group.nodes.name]
}
resource "ansible_playbook" "test" {
name = "all"
playbook = "site.yaml"
replayable = true
ansible_playbook_binary = "ansible-playbook"
ignore_playbook_failure = true
}
E falha com a seguinte mensagem:
ansible_playbook = <<EOT
[WARNING]: Found both group and host with same name: cluster
[WARNING]: Found both group and host with same name: all
PLAY [cluster] *******************************************************************
TASK [Gathering Facts] *********************************************************
fatal: [cluster]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname cluster: Temporary failure in name resolution", "unreachable": true}
PLAY RECAP *********************************************************************
cluster : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
EOT
ansible_playbook_errors = "exit status 4"
Não está claro para mim o que devo inserir no name
parâmetro ansible_playbook.test
e como devo configurar os hosts e grupos ansible. Você tem alguma sugestão?