Thank you very much for the reply. I'll do that 🙂
Le ven. 21 mai 2021 à 16:52, Matt Martz <[email protected]> a écrit : > The typical pattern is to pass the AnsibleModule instance to your > functions. > > On Fri, May 21, 2021 at 9:43 AM Gabriel Machado <[email protected]> > wrote: > >> Hi, >> >> I'm developping a module for linux with several functions. >> Most of the functions i develop need to launch binary executables. >> I know, the best practice is to use module.run_command() function to >> launch commands. But i instantiate the module object in the main() >> function. So, the module object cannot be used in the functions i develop. >> >> What should i do : >> - Pass the module as a variable to myfunctions (myfunctions(module)) ? >> - Instantiate another AnsibleModule object in each function ? >> - Use os.subprocess() function or equivalent in my functions ? >> >> Why using os.subprocess() is not recommended ? >> >> ### begin - code example ### >> myfunction1(module) >> return module.run_command("/usr/bin/ip route show")[1] >> >> def main(): >> module = AnsibleModule(argument_spec = dict()) >> result = dict() >> result['routes'] = myfunction1(module) >> >> return module.exit_json(**result) >> ### end - code example ### >> >> Have a nice weekend. >> Gabriel. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ansible Project" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/fbcc904e-5269-4d20-a0ba-09a244889df4n%40googlegroups.com >> <https://groups.google.com/d/msgid/ansible-project/fbcc904e-5269-4d20-a0ba-09a244889df4n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > Matt Martz > @sivel > sivel.net > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ansible Project" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/ansible-project/vqDIfUcD71w/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/CAD8N0v8Mdo0QeSDXXdHSUJexO7t0GYuXTwiO0R7fkhT5sNDhBg%40mail.gmail.com > <https://groups.google.com/d/msgid/ansible-project/CAD8N0v8Mdo0QeSDXXdHSUJexO7t0GYuXTwiO0R7fkhT5sNDhBg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFbTbD9MxC_KnmAYmABeEo4iDjsRQrh0XXxMPxpD9N%2BumMh-%3DA%40mail.gmail.com.
