# module argument parser is returning literal 'None' instead of logical 'None'

**URL:** <https://forum.ansible.com/t/module-argument-parser-is-returning-literal-none-instead-of-logical-none/12919>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [June 6, 2013, 11:00pm UTC](https://forum.ansible.com/t/module-argument-parser-is-returning-literal-none-instead-of-logical-none/12919 "2013-06-06T23:00:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 6, 2013, 11:00pm UTC](https://forum.ansible.com/t/module-argument-parser-is-returning-literal-none-instead-of-logical-none/12919/1 "2013-06-06T23:00:42Z")

</div>

Some thoughts:

You could probably do {% if x %}key={{x}}{% endif %}

Or even maybe {{ x or default\_value }}

But it may be easier and better to just have your system set a reasonable default if the value isn’t set.

---

<div class="post-metadata">

**Author:** ![Eugene\_Archibald](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@Eugene\_Archibald](https://forum.ansible.com/u/Eugene_Archibald)\
**Post date:** [June 6, 2013, 11:39pm UTC](https://forum.ansible.com/t/module-argument-parser-is-returning-literal-none-instead-of-logical-none/12919/2 "2013-06-06T23:39:26Z")

</div>

The problem is that there is no reasonable default value for some of these. For instance, uid: there are many disparate systems, some of which have e.g. userA defined on them as uid 503, and others may have userA defined as 505, and neither are more ‘correct’ than the other. I am bringing user distribution management under the ansible umbrella, but don’t want to try to change things like already-existing uids on systems.

More to the point, the user module appears to attempt to implement this behavior, but it will never receive [NoneType]None, only “None”:

def create\_user\_useradd(self, command\_name=‘useradd’):  
cmd = [self.module.get\_bin\_path(command\_name, True)]

if self.uid is not None:  
cmd.append(‘-u’)  
cmd.append(self.uid)

I have worked around it by changing the if self.uid and other parameter checks in user to include and self.uid != “None” for the moment, but it really seems like the module is not receiving these parameters with NoneType as it expects.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 6, 2013, 11:56pm UTC](https://forum.ansible.com/t/module-argument-parser-is-returning-literal-none-instead-of-logical-none/12919/3 "2013-06-06T23:56:16Z")

</div>

Yep, I think the solution here is to make the Ansible “Module Common” code auto convert “None” to None.

Can you please file a ticket for this, I may dig into this tonight but would like to have it tracked.

---

<div class="post-metadata">

**Author:** ![Eugene\_Archibald](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@Eugene\_Archibald](https://forum.ansible.com/u/Eugene_Archibald)\
**Post date:** [June 7, 2013, 12:05am UTC](https://forum.ansible.com/t/module-argument-parser-is-returning-literal-none-instead-of-logical-none/12919/4 "2013-06-07T00:05:38Z")

</div>

(That workaround was a terrible idea. I went with your idiom in the playbook instead, for now):

{% if x %}foo=x{% endif %}

Thanks!

---

<div class="post-metadata">

**Author:** ![Eugene\_Archibald](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@Eugene\_Archibald](https://forum.ansible.com/u/Eugene_Archibald)\
**Post date:** [June 7, 2013, 12:06am UTC](https://forum.ansible.com/t/module-argument-parser-is-returning-literal-none-instead-of-logical-none/12919/5 "2013-06-07T00:06:09Z")

</div>

I will file a ticket - leaving work now but it’s on my list.

Thanks!
