Last active
January 7, 2019 08:55
-
-
Save relaxdiego/5fd92ab7ded35fc955a046cf9b8f4dba to your computer and use it in GitHub Desktop.
Initialize in main() vs outside 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
#!/usr/bin/python | |
from ansible.module_utils.basic import AnsibleModule | |
def main(): | |
mod = AnsibleModule( | |
argument_spec=dict( | |
url=dict(required=True), | |
dest=dict(required=False, default="/tmp/firstmod") | |
) | |
) | |
save_data(mod) | |
def save_data(mod): | |
data = fetch_data(mod.params["url"]) | |
if write_data(data, mod.params["dest"]): | |
mod.exit_json(msg="Data saved", changed=True) | |
else: | |
mod.exit_json(msg="Up to date", changed=False) | |
def fetch_data(mod, url): | |
raise NotImplementedError | |
def write_data(data, dest): | |
raise NotImplementedError | |
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
#!/usr/bin/python | |
from ansible.module_utils.basic import AnsibleModule | |
def main(mod): | |
data = fetch_data(mod.params["url"]) | |
if write_data(data, mod.params["dest"]): | |
mod.exit_json(msg="Data saved", changed=True) | |
else: | |
mod.exit_json(msg="Up to date", changed=False) | |
def fetch_data(mod, url): | |
raise NotImplementedError | |
def write_data(data, dest): | |
raise NotImplementedError | |
if __name__ == '__main__': | |
mod = AnsibleModule( | |
argument_spec=dict( | |
url=dict(required=True), | |
dest=dict(required=False, default="/tmp/firstmod") | |
) | |
) | |
main(mod) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment