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

[optimize] Lazy-loaded WordPress inventory #491

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

domq
Copy link
Member

@domq domq commented Apr 8, 2022

This is a “same player shoots again” reincarnation of #434.

Loading the inventory from wordpress-instances.py takes some time (or even a long time) because it needs to find(1) all the sites over NFS. There is already support in the Ansible code base to skip roles/wordpress-instance when it can be worked out from the tags that we don't need it; this PR likewise makes sure to skip the useless inventory step.

  • Introduce a lazy_inventory inventory plugin, which discriminates between “lazy” and “diligent” modes according to the number of times it runs (i.e. one must run meta: refresh_inventory to get the full inventory)
  • Do exactly that in .interactive-playbooks/main.yml before we run roles/wordpress-instance. If we don't, then the all_wordpresses group stays empty (from the “fake” inventory) and therefore the role gets skipped, as it did before

Dominique Quatravaux and others added 5 commits April 8, 2022 09:55
This implements a “lazy” inventory source, that short-circuits to
something simpler the first time it runs. One must call
`- meta: refresh_inventory` from a play to get the full (presumably
more expensive to compute) inventory.

- Detect laziness from a global invocation counter (first run = lazy,
second and subsequent runs = “diligent” i.e. full inventory)
- Delegate to either ansible.plugins.inventory.script or
ansible.plugins.inventory.yaml as directed by configuration
- From wpsible, engage `lazy-wordpress-instances.yml` instead of `wordpress-instances.sh` when in ansible-playbook mode (i.e. laziness won't apply to `wpsible -m raw [...]`)
- Refactor ansible/.interactive-playbooks/main.yml to call `- meta: refresh_inventory` iff the tags require that we have a WordPress inventory — Otherwise we stay on the lazy one, i.e. empty `all_wordpresses` group, resulting in `roles/wordpress-instance` being skipped as it previously was
It doesn't even do anything without this ansible.cfg change
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

Successfully merging this pull request may close these issues.

1 participant