Created
September 3, 2024 14:44
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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