# access custom variables from inside play\_ontext.py

**URL:** <https://forum.ansible.com/t/access-custom-variables-from-inside-play-ontext-py/26528>\
**Category:** Ansible Developer\
**Created:** [January 22, 2018, 12:01pm UTC](https://forum.ansible.com/t/access-custom-variables-from-inside-play-ontext-py/26528 "2018-01-22T12:01:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![schick-dein-spam-und](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@schick-dein-spam-und](https://forum.ansible.com/u/schick-dein-spam-und)\
**Post date:** [January 22, 2018, 12:01pm UTC](https://forum.ansible.com/t/access-custom-variables-from-inside-play-ontext-py/26528/1 "2018-01-22T12:01:58Z")

</div>

Hi.  
I need to use a custom shell (/bin/bash wrapper with some additional options) when I need privilege escalation via sudo (become).  
For non-root tasks (no beomce) standard sh is needed. I have hacked make\_become\_cmd in play\_ontext.py to make it work but I would like to access a variable in there provided via cmd line arg (e.g. variable cause set via ansible-playbook --extra-vars “cause=reboot\_service\_after\_change” ?).

I have added:  
if self.become\_user == ‘root’:  
executable = ‘/usr/sbin/custom-root-sh’  
else:  
executable = ‘/usr/local/bin/custom-sh’  
And changed  
command = ‘%s -c %s’ % (executable, success\_cmd)  
to  
command = ‘%s -c %s **-v %s** ’ % (executable, success\_cmd, **shlex\_quote('“reboot\_service\_after\_change” ')**)

Instead, I want to read the example text “reboot\_service\_after\_change” from an variable provided via command line.  
How would that be possible?

thanks!  
Christof
