Skip to content

Instantly share code, notes, and snippets.

@relaxdiego relaxdiego/in_main.py
Last active Jan 7, 2019

Embed
What would you like to do?
Initialize in main() vs outside main()
#!/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()
#!/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
You can’t perform that action at this time.