# Default function treating variable as a string.

**URL:** <https://forum.ansible.com/t/default-function-treating-variable-as-a-string/37010>\
**Category:** Ansible Project\
**Created:** [August 19, 2022, 12:15pm UTC](https://forum.ansible.com/t/default-function-treating-variable-as-a-string/37010 "2022-08-19T12:15:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![farrukh\_ahmed](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@farrukh\_ahmed](https://forum.ansible.com/u/farrukh_ahmed)\
**Post date:** [August 19, 2022, 12:15pm UTC](https://forum.ansible.com/t/default-function-treating-variable-as-a-string/37010/1 "2022-08-19T12:15:24Z")

</div>

Hello Team,

Hope you all are doing well.  
Here is a case:

### Templates/php\_app.conf.j2

;# MANAGED BLOCK ###  
php\_admin\_flag[display\_errors] = {{server\_config.display\_errors}}  
php\_admin\_value[error\_log] = {{ server\_config.error\_log | default({“error\_log”:“{{base\_directory\_path }}/{{app\_name}}/logs/php-fpm\_error.log”}) }}  
php\_admin\_flag[log\_errors] = {{server\_config.log\_errors}}  
php\_admin\_flag[short\_open\_tag] = {{server\_config.short\_open\_tag}}  
php\_admin\_value[memory\_limit] = {{server\_config.memory\_limit}}  
php\_admin\_value[post\_max\_size] = {{server\_config.post\_max\_size}}  
php\_admin\_value[upload\_max\_filesize] = {{server\_config.upload\_max\_filesize}}  
php\_admin\_value[max\_input\_time] = {{server\_config.max\_input\_time}}  
php\_admin\_value[max\_execution\_time] = {{server\_config.max\_execution\_time}}  
php\_admin\_value[max\_file\_uploads] = {{server\_config.max\_file\_uploads}}  
php\_admin\_value[max\_input\_vars] = {{server\_config.max\_input\_vars}}  
php\_admin\_value[date.timezone] = {{server\_config.time\_zone}}  
;# MANAGED BLOCK ###

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [August 19, 2022, 12:21pm UTC](https://forum.ansible.com/t/default-function-treating-variable-as-a-string/37010/2 "2022-08-19T12:21:48Z")

</div>

You need one more “}” on your -e string to close out the server\_config.

ansible-playbook php\_config.yml -i hosts -e ‘{“app\_name”:“test-80php”,“base\_directory\_path”:“/var/www/html/applications/test-80php”,“server\_config”: **{** “display\_errors”:“Off”, “log\_errors”:“On”, “memory\_limit”:“200M”, “post\_max\_size”:“8M”, “upload\_max\_filesize”:“8M”, “max\_input\_time”:“60”, “max\_execution\_time”:“30”, “max\_file\_uploads”:“20”, “max\_input\_vars”:“2000”, “short\_open\_tag”:“On”, “time\_zone”:“Asia/Karachi” **}** }}’ -vvv  
------------------------------^

Walter

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [August 19, 2022, 12:37pm UTC](https://forum.ansible.com/t/default-function-treating-variable-as-a-string/37010/3 "2022-08-19T12:37:24Z")

</div>

That clearly didn’t display correctly …

You need three close braces at the end of your “-e” extra vars param.

**}** }}’ -vvv

Hope that helps.

---

<div class="post-metadata">

**Author:** ![farrukh\_ahmed](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@farrukh\_ahmed](https://forum.ansible.com/u/farrukh_ahmed)\
**Post date:** [August 20, 2022, 2:32pm UTC](https://forum.ansible.com/t/default-function-treating-variable-as-a-string/37010/4 "2022-08-20T14:32:15Z")

</div>

Here is the command previously used, I hope it is clearly visible.

ansible-playbook php\_config.yml -i hosts -e ‘{“app\_name”:“test-80php”,  
“base\_directory\_path”:“/var/www/html/applications/test-80php”,  
“server\_config”:{“display\_errors”:“Off”,  
“log\_errors”:“On”,  
“memory\_limit”:“200M”,  
“post\_max\_size”:“8M”,  
“upload\_max\_filesize”:“8M”,  
“max\_input\_time”:“60”,  
“max\_execution\_time”:“30”,  
“max\_file\_uploads”:“20”,  
“max\_input\_vars”:“2000”,  
“short\_open\_tag”:“On”,  
“time\_zone”:“Asia/Karachi”}}’ -vvv

Walter, I have tried adding more braces, but unfortunately, it didn’t work for me.  
The number of openings and closings braces is the same.

Regards,

Farrukh Ahmed

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [August 20, 2022, 4:29pm UTC](https://forum.ansible.com/t/default-function-treating-variable-as-a-string/37010/5 "2022-08-20T16:29:22Z")

</div>

Mustaches do not nest. The “error\_log” line in templates/php\_app.conf.j2 should be

```auto
php_admin_value[error_log] = {{ server_config.error_log | default(base_directory_path ~ "/" ~ "app_name/logs/php-fpm_error.log") }}

```

---

<div class="post-metadata">

**Author:** ![farrukh\_ahmed](https://avatars.discourse-cdn.com/v4/letter/f/a9adbd/32.png) [@farrukh\_ahmed](https://forum.ansible.com/u/farrukh_ahmed)\
**Post date:** [August 22, 2022, 7:04am UTC](https://forum.ansible.com/t/default-function-treating-variable-as-a-string/37010/6 "2022-08-22T07:04:02Z")

</div>

Thanks, Lewis for the solution. It actually worked. But would you mind explaining or sharing the documentation of what you have done above inside the “default()”?

I actually want to learn and understand this.

Thanks & regards,

Farrukh Ahmed
