I'm creating a requirements.yml
in an Ansible project, and I want to identify all of the modules that need to be installed from ansible-galaxy
that are used by project playbooks. ansible-doc --list --playbook-dir foo
seems like the right tool for the job, but it lists all locally available modules, not just the ones which are actually used in the foo
directory. ansible-galaxy list
doesn't account for any which are needed but not installed.
Is there a way to do this where I don't end up writing a shell script to sed|awk|grep
the info I want?
The best approach I've been able to come up with so far is to ansible-playbook --syntax-check
each of the playbooks. This will throw errors such as
ERROR! the role 'foo' was not found ...
ERROR! couldn't resolve module/action 'bar'. This often indicates a misspelling, missing collection, or incorrect module path.
but this is not ideal because it exits as soon as any error occurs. I have to fix each one and run the syntax check again.