Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform inventory groups contain invalid characters. #120

Open
queglay opened this issue Aug 14, 2019 · 5 comments
Open

Terraform inventory groups contain invalid characters. #120

queglay opened this issue Aug 14, 2019 · 5 comments

Comments

@queglay
Copy link

queglay commented Aug 14, 2019

Terraform Inventory seems to create groups with '.' characters in the groups. This delimiter in turn generates warnings from Ansible because they are invalid characters and produces a warning.

[WARNING]: Invalid characters were found in group names but not replaced

This is an example shell output when I provision with Ansible in Terraform.

module.workstation.null_resource.workstation_pcoip (local-exec): + ansible-playbook -i ansible/inventory ansible/node-centos-init-users.yaml -v --extra-vars variable_host=role_workstation_centos hostname=cloud_workstation1.example.com pcoip=true
module.workstation.null_resource.workstation_pcoip (local-exec): Using /vagrant/ansible.cfg as config file
module.workstation.null_resource.workstation_pcoip (local-exec): [DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to
module.workstation.null_resource.workstation_pcoip (local-exec): allow bad characters in group names by default, this will change, but still be
module.workstation.null_resource.workstation_pcoip (local-exec): user configurable on deprecation. This feature will be removed in version 2.10.
module.workstation.null_resource.workstation_pcoip (local-exec):  Deprecation warnings can be disabled by setting deprecation_warnings=False in
module.workstation.null_resource.workstation_pcoip (local-exec): ansible.cfg.
module.workstation.null_resource.workstation_pcoip (local-exec):  [WARNING]: Invalid characters were found in group names but not replaced, use
module.workstation.null_resource.workstation_pcoip (local-exec): -vvvv to see details
@KostyaEsmukov
Copy link

A workaround:

terraform-inventory "$@" | jq 'with_entries(.key |= sub("\\."; "_"))'

@obilodeau
Copy link
Contributor

Problematic code is here:

terraform-inventory/cli.go

Lines 167 to 168 in 94a66e3

// store as invdividual host (eg. <name>.<count>)
invdName := fmt.Sprintf("%s.%d", res.baseName, res.counter)

But I'm not sure if changing the . to a _ is a sufficient fix.

obilodeau added a commit to GoSecure/terraform-inventory that referenced this issue Oct 1, 2019
Starting with Ansible 2.8 dots (.) are no longer allowed in ansible groups: https://docs.ansible.com/ansible/latest/reference_appendices/config.html#transform-invalid-group-chars.

This patch fixes that problem by renaming host counts to use `_<count>` instead of `.<count>`.

Tests were fixed (and passes) but fixtures/ were left untouched.
@obilodeau
Copy link
Contributor

Tentative PR available here: #128

@jpmat296
Copy link

jpmat296 commented Jan 8, 2021

I have published a new "dev" release from my fork:
https://github.com/jpmat296/terraform-inventory/releases

It includes PR #128. This issue is fixed at least for me.

@rija
Copy link

rija commented Oct 3, 2023

Hi,
The merged PR only fix presence of dots in the the inventory groups, but my infrastructure on AWS generates system tags with hyphens, also illegal , so I have to filter out that group (as I don't need them):

terraform-inventory $@ ./ | jq 'with_entries(select([.key] | inside(["system_t3_micro-centos8"])|not))'

which I've generalised as

terraform-inventory $@ ./ | jq 'with_entries(select([.key] | contains(["system_"])|not))'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants