-
Bug
-
Resolution: Done
-
Undefined
-
None
-
Unspecified
-
False
-
-
False
-
-
https://github.com/ansible-collections/cloud.terraform/issues/114
-
-
-
-
- SUMMARY
Using [ansible terraform provider](https://github.com/ansible/terraform-provider-ansible) to add new hosts and groups for playbook.
- SUMMARY
-
-
-
When running `ansible-inventory -i inventory.yml --graph --vars` I get the following output although this was just deployed and not used in any playbook before
I am creating the group variables in the root `main.tf` and all hosts get added to the inventory in their respective modules.
Some information is left out like specific variables, IPs, and applications; however, the overall functionality is still the same
This is also ran in a docker container which gets created for each play.
I have already tried renaming the hosts to something unique each play but it still fails with the same message
Error
```
[WARNING]: * Failed to parse /deployment/ansible/inventory.yml with
ansible_collections.cloud.terraform.plugins.inventory.terraform_provider
plugin: Ansible Host es-role-name.zone.c.project.internal already exists elsewhere, please check your terraform
project(s)
[WARNING]: Unable to parse /deployment/ansible/inventory.yml as an inventory
source
[WARNING]: No inventory was parsed, only implicit localhost is available
```
-
-
-
-
- ISSUE TYPE
-
-
-
- Bug Report
-
-
-
-
- COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below, use your best guess if unsure -->
- COMPONENT NAME
-
-
-
collection: cloud.terraform.terraform_provider
plugin: inventory
-
-
-
-
- ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible [core 2.16.2]
config file = None
configured module search path = ['/Users/aleccarpenter/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
ansible collection location = /Users/aleccarpenter/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.11.6 (main, Oct 2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)] (/usr/local/opt/python@3.11/bin/python3.11)
jinja version = 3.1.2
libyaml = True
```
- ANSIBLE VERSION
-
-
-
-
-
-
-
- COLLECTION VERSION
<!--- Paste verbatim output from "ansible-galaxy collection list <namespace>.<collection>" between the quotes
for example: ansible-galaxy collection list community.general
-->
```paste below
- COLLECTION VERSION
-
-
-
- /Users/aleccarpenter/.ansible/collections/ansible_collections
Collection Version-
-
-
-
-
-
-
-
-
-
-
-
-
- -------
cloud.terraform 2.0.0
```
- -------
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
ACTION_WARNINGS(/Users/aleccarpenter/project/ansible/ansible.cfg) = False
ANSIBLE_FORCE_COLOR(/Users/aleccarpenter/project/ansible/ansible.cfg) = True
ANSIBLE_NOCOWS(/Users/aleccarpenter/project/ansible/ansible.cfg) = True
ANSIBLE_PIPELINING(/Users/aleccarpenter/project/ansible/ansible.cfg) = True
CALLBACKS_ENABLED(/Users/aleccarpenter/project/ansible/ansible.cfg) = ['timer', 'profile_tasks', 'profile_roles']
CONFIG_FILE() = /Users/aleccarpenter/project/ansible/ansible.cfg
DEFAULT_GATHERING(/Users/aleccarpenter/project/ansible/ansible.cfg) = smart
DEFAULT_LOG_PATH(/Users/aleccarpenter/project/ansible/ansible.cfg) = /Users/aleccarpenter/project/ansible/ansible.log
DEFAULT_PRIVATE_KEY_FILE(/Users/aleccarpenter/project/ansible/ansible.cfg) = /Users/aleccarpenter/project/id_rsa
HOST_KEY_CHECKING(/Users/aleccarpenter/project/ansible/ansible.cfg) = False
INVENTORY_ENABLED(/Users/aleccarpenter/project/ansible/ansible.cfg) = ['cloud.terraform.terraform_provider']
INVENTORY_IGNORE_EXTS(/Users/aleccarpenter/project/ansible/ansible.cfg) = ['[".yml"]']
PAGER(env: PAGER) = less
```
- CONFIGURATION
-
-
-
-
-
-
-
- OS / ENVIRONMENT
-
-
-
Running in docker container on macOS Sonoma 14.3.1
Terraform version = 1.7.3
Ansible version = 2.16.2
Docker version = 24.0.7
-
-
-
-
- STEPS TO REPRODUCE
-
-
-
Add example host to inventory with variables (this is in a module)
```text
resource "ansible_host" "elasticsearch" {
name = "es-${local.node_role}-${var.name}.${var.zone}.c.${var.project_id}.internal"
groups = ["elasticsearch"]
count = var.nodes_count
variables =
}
```
Add example variables to group (this is in the root `main.tf`)
```text
resource "ansible_group" "all" {
name = "all"
variables =
}
resource "ansible_group" "elastic" {
name = "elastic"
children = ["elasticsearch", "kibana", "agent", "fleet", "logstash"]
variables = {
}
}
```
inventory file
```yaml
—
plugin: cloud.terraform.terraform_provider
search_child_modules: true
project_path: ../tf/
```
Directory structure
```bash
.
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── ansible
│ ├── ansible.cfg
│ ├── ansible.log
│ ├── certs
│ ├── inventory.yml
│ ├── requirements.yaml
│ ├── roles
│ ├── site.yml
├── env
└── tf
├── vars.tf
├── main.tf
├── modules
├── outputs.tf
└── versions.tf
```
I run this multiple times with different names for each environment. No host has the same name
-
-
-
-
- EXPECTED RESULTS
when running `ansible-inventory -i inventory.yml --graph --vars -vvvv` I should be able to see all my hosts, groups, and variables.
- EXPECTED RESULTS
-
-
-
-
-
-
-
- ACTUAL RESULTS
-
-
-
Running `ansible-inventory -i inventory.yml --graph --vars -vvvv` gets me
```paste below
[WARNING]: * Failed to parse /deployment/ansible/inventory.yml with
ansible_collections.cloud.terraform.plugins.inventory.terraform_provider
plugin: Ansible Host es-role-name.zone.c.project.internal already exists elsewhere, please check your terraform
project(s)
[WARNING]: Unable to parse /deployment/ansible/inventory.yml as an inventory
source
[WARNING]: No inventory was parsed, only implicit localhost is available
ansible-inventory [core 2.16.2]
config file = /deployment/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-inventory
python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
jinja version = 3.0.3
libyaml = True
Using /deployment/ansible/ansible.cfg as config file
setting up inventory plugins
Loading collection cloud.terraform from /root/.ansible/collections/ansible_collections/cloud/terraform
Loading collection ansible.builtin from
File "/usr/local/lib/python3.10/dist-packages/ansible/inventory/manager.py", line 293, in parse_source
plugin.parse(self._inventory, self._loader, source, cache=cache)
File "/root/.ansible/collections/ansible_collections/cloud/terraform/plugins/inventory/terraform_provider.py", line 234, in parse
self.create_inventory(inventory, state_content, search_child_modules)
File "/root/.ansible/collections/ansible_collections/cloud/terraform/plugins/inventory/terraform_provider.py", line 206, in create_inventory
self._add_host(inventory, resource)
File "/root/.ansible/collections/ansible_collections/cloud/terraform/plugins/inventory/terraform_provider.py", line 179, in _add_host
raise TerraformWarning(
@all:
--@ungrouped: |
– {project = project} |
–
{router_fqdn = test.com}
``` |