#117 Error management in inventory scripts is dangerous
Opened 6 years ago by flepied. Modified 4 years ago

When you specify a test subject as a vm or a container, you want to isolate your host system from running a possibly destructive test. If for whatever reason the inventory script cannot start the vm or container, it will output no inventory and the test will default to run locally.

imo we should always output the corresponding inventory even if the resources are not available to avoid this side effect.


+1 this is one of the issues we encountered today with @psss

Metadata Update from @astepano:
- Issue assigned to astepano

6 years ago

Metadata Update from @astepano:
- Assignee reset

6 years ago

Metadata Update from @astepano:
- Issue assigned to mvadkert

6 years ago

While, localhost is always present implicitly, it will only match against a hosts: all pattern if it's explicitly included in the inventory. This can lead to lots of confusion and problems (such as this issue), where you need localhost to be part of the play sometimes, but not for every role/task.

The easiest way I've found to deal with this, is to not use the hosts: all pattern. Instead, for example you could do:

hosts: subjects

and

hosts: localhost

Otherwise (with hosts: all) you're often left in a lurch and need to spread ugly things like this all around:

...
    roles:
        - role: blah
          when: "inventory_hostname != 'localhost'"
...

While sometimes that has its place, it's often easier to simply separate the localhost completely in it's own play. For example:

- hosts: localhost
  ...localhost stuff...

- hosts: subjects
  ...subject stuff...

For cases where you really do want both to be part of the play, then you can explicitly mention it as the pattern:

- hosts: subjects|localhost
  ...stuff...

Hope that helps.

@bgoncalv this is still not solved in current implementation right?

not by the roles, we have some workaround on downstream where we to the provision first and make sure it worked, and just then we run the playbook.

not by the roles

This is best. Ansible is great at managing late-stage setup and configuration minutiae. Not so much for fundamental creation and bootstrapping. Use purpose-built tooling for that, like Packer & Terraform (or similar), then bring in Ansible last. i.e. after networking and basic ssh/remote access is setup.

This is also a much easier architecture to automate the testing of the frameworks themselves.

Login to comment on this ticket.

Metadata