# action plugin: modify task\_vars?

**URL:** <https://forum.ansible.com/t/action-plugin-modify-task-vars/33325>\
**Category:** Ansible Developer\
**Created:** [July 6, 2020, 8:12am UTC](https://forum.ansible.com/t/action-plugin-modify-task-vars/33325 "2020-07-06T08:12:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregory\_Christy](https://avatars.discourse-cdn.com/v4/letter/g/ecccb3/32.png) [@Gregory\_Christy](https://forum.ansible.com/u/Gregory_Christy)\
**Post date:** [July 6, 2020, 8:12am UTC](https://forum.ansible.com/t/action-plugin-modify-task-vars/33325/1 "2020-07-06T08:12:48Z")

</div>

Hello everybody,

originally I’ve posted this question in the ansible-project group ([https://groups.google.com/forum/#!topic/ansible-project/H9puBxsC0ww](https://groups.google.com/forum/#!topic/ansible-project/H9puBxsC0ww)) but without any responses. So I’m reposting it here.

I have a custom module and would like to set the ansible\_python\_interpreter variable from within a corresponding action plugin.  
This is what I do in the action plugin:

`task_vars_modified = task_vars.copy()`  
`task_vars_modified['ansible_python_interpreter'] = '<path/to/my/python>'`  
`result = merge_hash(result, self._execute_module(module_args=module_args, task_vars=task_vars_modified))`

Unfortunately this has no effect. Using the playbook debugger I can verify that ansible\_python\_interpreter is not set for the module.  
I am sure that the action plugin is called.  
What am I doing wrong?  
Is it possible at all to modify task\_vars? I cannot find an example for this approach.  
Please note that I’m using delegate\_to in the task. I admit, I haven’t tried without delegate\_to, yet.

Background:  
My custom module makes use of some python modules. I do not want to install these modules globally so I’m using a virtual environment.  
Obviously now the ansible module needs to use the python binary within the virtual environment.  
I would like to encapsulate this so that the user does not have to remember to set ansible\_python\_interpreter each time he uses the module.

Thanks and Regards,  
Carsten
