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

Switch from inventory file to directory for testinfra call #2962

Merged

Conversation

amarao
Copy link
Contributor

@amarao amarao commented Nov 10, 2020

PR Type

  • Feature Pull Request

It should allow to use hostvars of non-managed hosts inside testinfra call (including delegation). See Issue #2961 for details.

(should respect linked hosts and allow to use `hostvars[linked_host]`).
@amarao amarao changed the title Switch from inventory form file to directory for testinfra call Switch from inventory from file to directory for testinfra call Nov 11, 2020
@amarao amarao changed the title Switch from inventory from file to directory for testinfra call Switch from inventory file to directory for testinfra call Nov 11, 2020
@ssbarnea ssbarnea added the bug label Nov 12, 2020
@ssbarnea
Copy link
Member

@amarao Does this break users that do not have a directory? Ansible allows both files or directory approach and if we implement support for folders while breaking the flat-inventory users we are in bit trouble, especially because the number of users using simple inventories is greater.

@cloudnull
Copy link
Contributor

👍 to what @ssbarnea said, I'd like know this doesn't break existing use-cases.

Copy link
Contributor

@cloudnull cloudnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we configure the provisioner with both file and directory support?

@amarao
Copy link
Contributor Author

amarao commented Nov 13, 2020

@ssbarnea, When molecule constructs inventory, it writes ansible_inventory.yaml. Current behavior: the path to this inventory file is then passed to testinfra: (self._config.provisioner.inventory_file). Proposed behavior: write the same file, but pass the directory (self._config.provisioner.inventory_directory,) with ansible_inventory.yaml inside it as an inventory.

As far as I understand ansible, there is no difference between inventory file and an inventory directory with the same file inside. Ansible reads all yaml files from the inventory directory, so 'inventory file' is used in both cases. The difference is only if there are additional files. (This is the case with 'linked' hosts and group/hostvars directories). Group vars and Host vars are not affected, because host_group_vars plugin is searching them in both cases (file and directory).

If user used only constructed inventory (no links), then Ansible will read directory with a single file, no issues.
If user used links, than Ansible (under testinfra) start to see those links. (This is the reason for patch - I want to access data from hosts link).

The single issue I found is that tests may start to run against linked host, but it's easily solved:

verifier:
  name: testinfra
  options:
    force-ansible: true
    hosts: vms

(I have 'hypervisor' linked host and vms are provisioned and tested).

@ssbarnea ssbarnea merged commit 94624bc into ansible:master Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants