The following code is in the defaults/main.yml file for a role:
file_env: "{% if cf_env is equalto 'cf10_dev' %}
dev
{% elif cf_env is equalto 'cf10_stg' %}
stg
{% elif (cf_env is equalto 'cf10_prd') or (cf_env is equalto 'cf10_prd_ext') %}
prd
{% elif cf_env is equalto 'cf11' %}
[dev, prd]
{% endif %}"
The first 3 conditional statements work fine, where the file_env
var is set to a single value, but when trying to set the file_env
var to a list (the last elif statement), it doesn't work:
failed: [server-new.xxx.com] (item=[dev, prd] ) => {"ansible_loop_var": "item", "changed": false, "item": "[dev, prd] ", "msg": "Destination /opt/coldfusion11/[dev, prd] 01/bin/jvm.config does not exist !", "rc": 257}
Here is the task that generates the above error:
- name: Update jvm.config for coldfusion11 server
lineinfile:
path: /opt/coldfusion11/{{ item }}01/bin/jvm.config
regexp: '^java.home'
line: 'java.home=/usr/lib/jvm/jre-openjdk'
loop:
- "{{ file_env }}"
notify:
- handler_create_script_list
- handler_restart_coldfusion10
when:
- cf_env == "cf11"
How can I set the file_env
var to a list?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…