# extending a module, try/finally

**URL:** <https://forum.ansible.com/t/extending-a-module-try-finally/17716>\
**Category:** Ansible Developer\
**Tags:** ansible-devel\
**Created:** [March 11, 2015, 6:46am UTC](https://forum.ansible.com/t/extending-a-module-try-finally/17716 "2015-03-11T06:46:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mirko\_Friedenhagen](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mirko\_Friedenhagen](https://forum.ansible.com/u/Mirko_Friedenhagen)\
**Post date:** [March 11, 2015, 6:46am UTC](https://forum.ansible.com/t/extending-a-module-try-finally/17716/1 "2015-03-11T06:46:31Z")

</div>

Hello,

is there a way to invoke other modules? Basically, I want to do this:

tmp = template(password\_script, mode=0700)  
try:  
synchronize(args, SUDO\_ASKPASS=tmp)  
finally:  
os.remove(tmp)

Is this possible or do I have to copy-n-paste code here?

Regards  
Mirko

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [March 11, 2015, 7:56am UTC](https://forum.ansible.com/t/extending-a-module-try-finally/17716/2 "2015-03-11T07:56:39Z")

</div>

That’s a feature expected in the 2.0 release.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [March 11, 2015, 3:43pm UTC](https://forum.ansible.com/t/extending-a-module-try-finally/17716/3 "2015-03-11T15:43:31Z")

</div>

Yes, this will be easier to do in 2.0. However, to do it today you can set “ignore\_errors: yes” on the task while registering the result, and then have a follow-up task which runs when the previous result failed.

For example:

- command: /bin/false  
ignore\_errors: yes  
register: failed\_result

- command: /do/something/else  
when: failed\_result|failed

Hope that helps!
