setup-hosts.yml does not work correctly when combined with --limit

Bug #2041717 reported by Damian Dąbrowski
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack-Ansible
Fix Released
Undecided
Unassigned

Bug Description

Issue description
=================

In major upgrade guide [1], it is suggested to run setup-hosts.yml in a following manner:

openstack-ansible setup-hosts.yml --limit '!galera_all:!rabbitmq_all' -e package_state=latest
openstack-ansible setup-hosts.yml -e 'lxc_container_allow_restarts=false' --limit 'galera_all:rabbitmq_all'

The crucial thing is that setup-hosts.yml imports playbooks like certificate-authority.yml and certificate-generate.yml that are supposed to run on localhost by default.
Unfortunately, when --limit is used, playbook is not executed against localhost which may lead to several unexpected issues.

Steps to reproduce
==================

# openstack-ansible certificate-authority.yml --limit '!galera_all:!rabbitmq_all' --list-hosts

## OUTPUT

playbook: certificate-authority.yml

  play #1 (localhost): Create CA certificates TAGS: [always]
    pattern: ['localhost']
    hosts (0):

## EXPECTED OUTPUT

playbook: certificate-authority.yml

  play #1 (localhost): Create CA certificates TAGS: [always]
    pattern: ['localhost']
    hosts (1):
      localhost

Explanation
===========

It happens because implicit localhost[2] is not a part of 'all' nor any other group.[3]

Possible solutions
==================

1. Add localhost explicitly to the inventory. It will then match the 'all' group in our playbooks too with all undesired possible effects, but i think it's not a problem with OSA because we don't run any playbooks against 'all' group.

2. Add 'all' and 'localhost' to --limit(--limit 'localhost:all:!galera_all:!rabbitmq_all') but it will solve the problem only for the case described above while the problem may not be limited only to this single case. That's why I'm leaning towards solution 1.

Links
=====

[1] https://docs.openstack.org/openstack-ansible/latest/admin/upgrades/major-upgrades.html
[2] https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html#implicit-localhost
[3] https://stackoverflow.com/questions/73706195/using-limit-flag-with-ansible-playbook-causes-localhost-to-not-be-found

summary: - setup-hosts.yml does not run correctly when combined with --limit
+ setup-hosts.yml does not work correctly when combined with --limit
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to openstack-ansible (master)
Changed in openstack-ansible:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to openstack-ansible (master)

Reviewed: https://review.opendev.org/c/openstack/openstack-ansible/+/899523
Committed: https://opendev.org/openstack/openstack-ansible/commit/8f3c02d2da3059afa4ed6a2066024b98a3c64162
Submitter: "Zuul (22348)"
Branch: master

commit 8f3c02d2da3059afa4ed6a2066024b98a3c64162
Author: Damian Dabrowski <email address hidden>
Date: Sat Oct 28 14:58:15 2023 +0200

    Explicitly add localhost to inventory.ini

    Because implicit localhost is not a part of 'all' or any other group,
    playbooks executed with '--limit' may not take it into account.
    The problem was extensively described in bug #2041717.

    This change explicitly adds localhost to OSA inventory to avoid
    unexpected behavior.

    Closes-Bug: #2041717
    Change-Id: Ib44ed22d7132b42a4185a91f12c66ced5a1a6209

Changed in openstack-ansible:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to openstack-ansible (stable/2023.1)

Fix proposed to branch: stable/2023.1
Review: https://review.opendev.org/c/openstack/openstack-ansible/+/900598

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to openstack-ansible (stable/zed)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to openstack-ansible (stable/yoga)

Fix proposed to branch: stable/yoga
Review: https://review.opendev.org/c/openstack/openstack-ansible/+/900600

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to openstack-ansible (stable/2023.1)

Reviewed: https://review.opendev.org/c/openstack/openstack-ansible/+/900598
Committed: https://opendev.org/openstack/openstack-ansible/commit/be52bb288877c9557d2eeef0e6691cf448ae669d
Submitter: "Zuul (22348)"
Branch: stable/2023.1

commit be52bb288877c9557d2eeef0e6691cf448ae669d
Author: Damian Dabrowski <email address hidden>
Date: Sat Oct 28 14:58:15 2023 +0200

    Explicitly add localhost to inventory.ini

    Because implicit localhost is not a part of 'all' or any other group,
    playbooks executed with '--limit' may not take it into account.
    The problem was extensively described in bug #2041717.

    This change explicitly adds localhost to OSA inventory to avoid
    unexpected behavior.

    Closes-Bug: #2041717
    Change-Id: Ib44ed22d7132b42a4185a91f12c66ced5a1a6209
    (cherry picked from commit 8f3c02d2da3059afa4ed6a2066024b98a3c64162)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to openstack-ansible (stable/zed)

Reviewed: https://review.opendev.org/c/openstack/openstack-ansible/+/900599
Committed: https://opendev.org/openstack/openstack-ansible/commit/6288a73ebed4f43bc0915062c97242610a35cd52
Submitter: "Zuul (22348)"
Branch: stable/zed

commit 6288a73ebed4f43bc0915062c97242610a35cd52
Author: Damian Dabrowski <email address hidden>
Date: Sat Oct 28 14:58:15 2023 +0200

    Explicitly add localhost to inventory.ini

    Because implicit localhost is not a part of 'all' or any other group,
    playbooks executed with '--limit' may not take it into account.
    The problem was extensively described in bug #2041717.

    This change explicitly adds localhost to OSA inventory to avoid
    unexpected behavior.

    Closes-Bug: #2041717
    Change-Id: Ib44ed22d7132b42a4185a91f12c66ced5a1a6209
    (cherry picked from commit 8f3c02d2da3059afa4ed6a2066024b98a3c64162)

tags: added: in-stable-zed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to openstack-ansible (stable/yoga)

Reviewed: https://review.opendev.org/c/openstack/openstack-ansible/+/900600
Committed: https://opendev.org/openstack/openstack-ansible/commit/302842f884f0da0d027e0894ed150589cae3b362
Submitter: "Zuul (22348)"
Branch: stable/yoga

commit 302842f884f0da0d027e0894ed150589cae3b362
Author: Damian Dabrowski <email address hidden>
Date: Sat Oct 28 14:58:15 2023 +0200

    Explicitly add localhost to inventory.ini

    Because implicit localhost is not a part of 'all' or any other group,
    playbooks executed with '--limit' may not take it into account.
    The problem was extensively described in bug #2041717.

    This change explicitly adds localhost to OSA inventory to avoid
    unexpected behavior.

    Closes-Bug: #2041717
    Change-Id: Ib44ed22d7132b42a4185a91f12c66ced5a1a6209
    (cherry picked from commit 8f3c02d2da3059afa4ed6a2066024b98a3c64162)

tags: added: in-stable-yoga
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/openstack-ansible 27.3.0

This issue was fixed in the openstack/openstack-ansible 27.3.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/openstack-ansible 25.6.0

This issue was fixed in the openstack/openstack-ansible 25.6.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/openstack-ansible 26.4.0

This issue was fixed in the openstack/openstack-ansible 26.4.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/openstack-ansible 28.0.0.0rc1

This issue was fixed in the openstack/openstack-ansible 28.0.0.0rc1 release candidate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.