# Escaping percent % sign in a module

**URL:** <https://forum.ansible.com/t/escaping-percent-sign-in-a-module/18609>\
**Category:** Ansible Developer\
**Created:** [June 25, 2015, 6:09pm UTC](https://forum.ansible.com/t/escaping-percent-sign-in-a-module/18609 "2015-06-25T18:09:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Matz1](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@Guy\_Matz1](https://forum.ansible.com/u/Guy_Matz1)\
**Post date:** [June 25, 2015, 6:09pm UTC](https://forum.ansible.com/t/escaping-percent-sign-in-a-module/18609/1 "2015-06-25T18:09:34Z")

</div>

Hi! I’ve written a module and am bumping up against an issue when I try to include a percent sign in one of the parameters, e.g.:

supervisor\_prog:  
name: smlp-data  
user: smlp  
command: java blah-blah-blah  
environment: PATH=‘/usr/java/jdk1.8.0\_11/bin:%(ENV\_PATH)s’

Notice the % sign in the environment param above . . . that’s causing ConfigParser to choke with:  
ConfigParser.InterpolationMissingOptionError: Bad value substitution:  
section: [program:smlp-data]  
option : environment  
key : env\_path  
rawval : ’

the problem is with the ConfigParser module . . . I have a supervisor config that has the line:  
environment: PATH=‘/usr/java/jdk1.8.0\_11/bin:%(ENV\_PATH)s’

and ConfigParser chokes whenever it tries to process that line:

> > > from ConfigParser import SafeConfigParser  
> > > c = SafeConfigParser()  
> > > c.read(‘/etc/supervisor.d/sidecar-data’)  
> > > [‘/etc/supervisor.d/sidecar-data’]  
> > > c.sections()  
> > > [‘program:sidecar-data’]  
> > > c.items(‘program:sidecar-data’)  
> > > Traceback (most recent call last):  
> > > File “”, line 1, in   
> > > File “/usr/lib64/python2.6/ConfigParser.py”, line 578, in items  
> > > for option in options]  
> > > File “/usr/lib64/python2.6/ConfigParser.py”, line 614, in \_interpolate  
> > > self.\_interpolate\_some(option, L, rawval, section, vars, 1)  
> > > File “/usr/lib64/python2.6/ConfigParser.py”, line 646, in \_interpolate\_some  
> > > option, section, rest, var)  
> > > ConfigParser.InterpolationMissingOptionError: Bad value substitution:  
> > > section: [program:sidecar-data]  
> > > option : environment  
> > > key : env\_path  
> > > rawval : ’

I know this isn’t the configparser mailing list, but I was hoping someone might have some idea of how I can get configparser to behave.

Thanks a lot!!

---

<div class="post-metadata">

**Author:** ![Jonathan\_Davila](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@Jonathan\_Davila](https://forum.ansible.com/u/Jonathan_Davila)\
**Post date:** [June 29, 2015, 6:08pm UTC](https://forum.ansible.com/t/escaping-percent-sign-in-a-module/18609/2 "2015-06-29T18:08:54Z")

</div>

Have you tried this by leveraging gathered facts?

`  
environment:  
PATH:“/usr/java/jdk1.8.0\_11/bin:{{ansible\_env.ENV\_PATH}}”

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 2, 2015, 10:10pm UTC](https://forum.ansible.com/t/escaping-percent-sign-in-a-module/18609/3 "2015-07-02T22:10:34Z")

</div>

So config parser tries to do python substitutions which %(anyting)s  
looks like a named string, use %% to escape percent signs in this  
case.

But that probably breaks your module which will try to do exactly the  
same thing, so I recommend you follow Jonathan's suggestion.
