# How do I correctly pass NULL in set\_fact ?

**URL:** <https://forum.ansible.com/t/how-do-i-correctly-pass-null-in-set-fact/36113>\
**Category:** Ansible Project\
**Created:** [December 15, 2021, 12:40pm UTC](https://forum.ansible.com/t/how-do-i-correctly-pass-null-in-set-fact/36113 "2021-12-15T12:40:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anthony\_Palermo](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@Anthony\_Palermo](https://forum.ansible.com/u/Anthony_Palermo)\
**Post date:** [December 15, 2021, 12:40pm UTC](https://forum.ansible.com/t/how-do-i-correctly-pass-null-in-set-fact/36113/1 "2021-12-15T12:40:06Z")

</div>

I am not able to pass a NULL to community.mysql.mysql\_query but I think the issue is independent from the module

> <https://gist.github.com/aworldofcode/35de280946fabcc66e2eea15c8a13dd8>

# mariadb sql table includes the following column

`date_of_removal` datetime DEFAULT NULL,

# The Key Dict is either

‘main\_dict.removal\_info is defined’: ‘2021-12-19 21:50:43’ # a datetime properly formated  
‘main\_dict.removal\_info is defined’: ‘N/A’ # A string

# The goal is to properly provide a Null when ‘N/A’ is present

# Meanwhile in Ansible set\_fact

- name: Set the etl\_dictionary Key Value Dictionary from main\_dict request  
set\_fact:  
etl\_dictionary: \>-  
{

{% if main\_dict.removal\_info is defined -%}  
{% if ‘N/A’ in main\_dict.removal\_info -%}  
“date\_of\_removal”: ‘Null’ ,  
{% else %}  
“date\_of\_removal”: “{{main\_dict.removal\_info}}”,  
{% endif %}  
{% endif %}

}

# SQL Statement

# Cannot execute SQL 'INSERT INTO … ‘N/A’, ‘No’, ‘null’, ‘N/A’ The expected behaviour to achieve is … ‘N/A’, ‘No’, Null, ‘N/A’

how would I pass correctly null in a set\_fact ?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 15, 2021, 7:25pm UTC](https://forum.ansible.com/t/how-do-i-correctly-pass-null-in-set-fact/36113/2 "2021-12-15T19:25:35Z")

</div>

> I am not able to pass a NULL to community.mysql.mysql\_query but I think the issue is independent from the module
> 
> [https://gist.github.com/aworldofcode/35de280946fabcc66e2eea15c8a13dd8](https://gist.github.com/aworldofcode/35de280946fabcc66e2eea15c8a13dd8)
> 
> # mariadb sql table includes the following column  
> `date_of_removal` datetime DEFAULT NULL,
> 
> # The Key Dict is either  
> 'main\_dict.removal\_info is defined': '2021-12-19 21:50:43' # a datetime properly formated  
> 'main\_dict.removal\_info is defined': 'N/A' # A string
> 
> # The goal is to properly provide a Null when 'N/A' is present
> 
> # Meanwhile in Ansible set\_fact
> 
> - name: Set the etl\_dictionary Key Value Dictionary from main\_dict request  
> set\_fact:  
> etl\_dictionary: \>-  
> {
> 
> {% if main\_dict.removal\_info is defined -%}  
> {% if 'N/A' in main\_dict.removal\_info -%}  
> "date\_of\_removal": 'Null' ,  
> {% else %}  
> "date\_of\_removal": "{{main\_dict.removal\_info}}",  
> {% endif %}
> 
> }
> 
> # SQL Statement  
> # Cannot execute SQL 'INSERT INTO .... 'N/A', 'No', 'null', 'N/A' The expected behaviour to achieve is ... 'N/A', 'No', Null, 'N/A'
> 
> how would I pass correctly null in a set\_fact ?

I think that the Python keyword None (without quotes around) is the equivalent of a null value and should translate to NULL in the SQL world.  
Not tested though.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
