Open Midnighter opened 1 year ago
Better to use a Github runner / Github Actions Ci/Cd pipeline to execute the Terraform / Ansible rather than the land and expand approach. I hope this helps.
I could do that with jumping hosts, yes. The point is that I can only ever have a single VM exposed to the public directly.
My main point is that at least to an Ansible newbie like myself, the existing documentation and artificial examples are not enough to figure out how to actually use this provider in practice.
Completely agree with the sentiment. I think Ansible is the right too for what I want to do, I even have a working playbook that I can run with ansible-playbook, but I wanted to connect it to my existing terraform setup and it's been super hard to really understand what is going on.
For example, everytime I run this I get
╷
│ Error: Plugin did not respond
│
│ with module.distr.ansible_playbook.user_root,
│ on ../../modules/distributed_workers/main.tf line 17, in resource "ansible_playbook" "user_root":
│ 17: resource "ansible_playbook" "user_root" {
│
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
``
Which really doesn't say much about what went wrong.
on your client or on your cloud shell where you run ansible, you must first install: ansible-galaxy collection install cloud.terraform --force ansible-galaxy collection install community.general --force
in your provider.tf also must be ansible:
ansible = {
#version = "~> 1.1.0"
source = "ansible/ansible"
plugin: cloud.terraform.terraform_provider
when you have all this, and you create a infrastructure, on the end you can make a ansible-inventory -i inventory.yml --graph
it should show you now your hosts: @all: |--@ungrouped: |--@postgres_hosts: | |--37.117.241.9
in my main.tf i have following entry: resource "ansible_host" "postgres" { count = var.countvm name = azurerm_public_ip.postgres[count.index].ip_address groups = ["postgres_hosts"] variables = { ansible_user = "${var.local_os_admin}", ansible_ssh_private_key_file = "${var.ansible_ssh_key}", ansible_python_interpreter = "${var.ansible_python}", } }
ok, at the moment i must run terraform apply twice, because first apply it bring me issue53 failure, after apply again, it generates the inventory correct!
regards franco
I think they should add this to docs... :D
on your client or on your cloud shell where you run ansible, you must first install: ansible-galaxy collection install cloud.terraform --force ansible-galaxy collection install community.general --force
in your provider.tf also must be ansible:
ansible = { #version = "~> 1.1.0" source = "ansible/ansible"
than you must add to your terraform project directory the "inventory.yml" with this line in:
plugin: cloud.terraform.terraform_provider
when you have all this, and you create a infrastructure, on the end you can make a ansible-inventory -i inventory.yml --graph
it should show you now your hosts: @ALL: |--@Ungrouped: |--@postgres_hosts: | |--37.117.241.9
in my main.tf i have following entry: resource "ansible_host" "postgres" { count = var.countvm name = azurerm_public_ip.postgres[count.index].ip_address groups = ["postgres_hosts"] variables = { ansible_user = "${var.local_os_admin}", ansible_ssh_private_key_file = "${var.ansible_ssh_key}", ansible_python_interpreter = "${var.ansible_python}", } }
ok, at the moment i must run terraform apply twice, because first apply it bring me issue53 failure, after apply again, it generates the inventory correct!
regards franco
Being quite new to Ansible, I find the documentation leaving a lot to be desired for. My suggestions for improvements:
My own scenario: I'm running terraform from my workstation and set up some OpenStack instances. I have one instance that is accessible to the public net by SSH with a key. I would like to run an Ansible playbook on that node and let it connect to other instances in the same subnet to install further software. I couldn't figure it out.