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
On Saturday, August 20, 2022 at 9:30:26 PM UTC+5 [email protected] wrote:

> Mustaches do not nest. The "error_log" line in templates/php_app.conf.j2 
> should be
>
> php_admin_value[error_log] = {{ server_config.error_log | 
> default(base_directory_path ~ "/" ~ "app_name/logs/php-fpm_error.log") }}
>
>
> On 8/19/22 8:15 AM, farrukh ahmed wrote:
>
> 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 ###
> ####
>
>
> ### Tasks/main.yml
> - name: Copy template of PHP configuration
> template:
> src: "../templates/php_app.conf.j2"
> dest: "{{ php_app_configs_path }}/{{ app_name }}.conf"
> backup: yes
> #####
>
> ### Defaults/main/yml
> php_app_configs_path: "/home/farrukh/php"
> server_config: {
> display_errors: "On",
> error_log: "{{ base_directory_path }}/{{ app_name 
> }}/logs/php-fpm_error.log",
> log_errors: "On",
> short_open_tag: "Off",
> memory_limit: 128M,
> post_max_size: 8M,
> upload_max_filesize: 2M,
> max_input_time: 60, 
> max_execution_time: 30,
> max_file_uploads: 20,
> max_input_vars: 1000,
> time_zone: UTC
> } 
> ####
>
> Here is the command I ran:
>
> 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
>
> After Running the command, the template file output. It is treated as a 
> string but not as a variable. 
> For instance, If I don't pass the variable "error_log" variable from CLI, 
> its value should put the value in the template file as the variables 
> defined, should be like i.e(*php_admin_value[error_log] = 
> /var/www/html/applications/test-80php/logs/php-fpm_error.log*) in the 
> template file
>
> But it is treated as the string like the below code:
> ;# MANAGED BLOCK ###
> php_admin_flag[display_errors] = Off
> php_admin_value[error_log] = {'error_log': '{{base_directory_path }}/{
> {app_name}}/logs/php-fpm_error.log'}
> php_admin_flag[log_errors] = On
> php_admin_flag[short_open_tag] = Off
> php_admin_value[memory_limit] = 200M
> php_admin_value[post_max_size] = 8M
> php_admin_value[upload_max_filesize] = 8M
> php_admin_value[max_input_time] = 120
> php_admin_value[max_execution_time] = 30
> php_admin_value[max_file_uploads] = 60
> php_admin_value[max_input_vars] = 2000
> php_admin_value[date.timezone] = Asia/Islamabad
> ;# MANAGED BLOCK ###
>
> Am I doing it the right way? Any help or solution will be appreciated
>
> Thanks
>
> Farrukh Ahmed.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/272f52d9-4038-44ff-958c-4446abaf00e2n%40googlegroups.com.

Reply via email to