Using Foreman-WebUI for Configmgt with Ansible

Whats the way to go with Foreman and Ansible to Manage Files?

What I learned is that using jinja-templates in roles is the way how to override certain variables in the foreman-WebUI. But how to cope with cases where for instance a file would need not only overriding certain variables but append further lines to a jinja-template? How should one manage host-specific overrides of a file in the foreman-WebUI where multiple lines are required?

Example: Jinja-Template /etc/profile.d/foo consists of following lines

export VAR1
export VAR2
export VAR3

How could one not only override theses 3 variables in the Foreman-WebUI but also append further X Variables/Functions/Text to a file leading to following result (example02):

export VAR1
export VAR2
export VAR3
function clusterstate() {
timeout 2 mysql -u root -e "SHOW GLOBAL STATUS LIKE 'wsrep_%'" | grep -E "wsrep_cluster_state_uuid|wsrep_cluster_size|wsrep_cluster_status|wsrep_evs_state|wsrep_ready|wsrep_connected|wsrep_local_state_comment" | column -t
}
export VAR4

I tried to create a variable in the role which is by default empty and use it at the end of the jinja-template-file with the intention to override this variable in the foreman-WebUI. If the variable is a online string its working as expected but is it somehow possible to just put multiple lines by copy paste (with carriage returns) into such a variable to lead to a result as in example02?
Tests showed that its not possible and Foreman-WebUI passes these multiple lines without any carriage return into the template and consequently in the file which leads to following result:

export VAR1
export VAR2
export VAR3
function clusterstate() { timeout 2 mysql -u root -e "SHOW GLOBAL STATUS LIKE 'wsrep_%'" | grep -E "wsrep_cluster_state_uuid|wsrep_cluster_size|wsrep_cluster_status|wsrep_evs_state|wsrep_ready|wsrep_connected|wsrep_local_state_comment" | column -t }  function myconn() { aa="$(timeout 2 mysql -u root -e "SHOW PROCESSLIST" |wc -l)" count=$(expr $aa - 4) echo "active connections on this node: $count" } export VAR4

So my question is how one should cope with such use-cases or is there a complete other approach necessary?