Skip to content

Instantly share code, notes, and snippets.

@simonLeary42
Created September 3, 2024 14:44
Show Gist options
  • Save simonLeary42/699aedc93bbe69fa97620eacb93ab5e8 to your computer and use it in GitHub Desktop.
Save simonLeary42/699aedc93bbe69fa97620eacb93ab5e8 to your computer and use it in GitHub Desktop.
don't use the `stat` module on each, that's too slow. Instead, do all at once
# ansible module
import os
from ansible.module_utils.basic import AnsibleModule
def main():
module = AnsibleModule(
argument_spec=dict(
paths=dict(type="list", required=True),
follow=dict(type="bool", default=True),
),
supports_check_mode=True,
)
output = {path: os.path.exists(path) for path in module.params["paths"]}
module.exit_json(changed=False, paths_existence=output)
if __name__ == "__main__":
main()
# in an ansible action plugin
existence_check_results = self._execute_module(
module_name="unity.copy_recursive._do_paths_exist",
module_args={"paths": destination_dirs},
task_vars=task_vars,
)
paths_existence = existence_check_results["paths_existence"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment