Sugiro esta solução:
---
- set_fact:
composer_opts: ""
when: "{{env}}" == 'dev'
Ele definirá composer_opts
variable como string ""
quando a variável env
for igual a ' dev
'.
Aqui está um exemplo de uma cartilha com base em uma pergunta atualizada:
$ cat test.yml
---
- hosts: 127.0.0.1
connection: local
tasks:
- set_fact:
composer_opts: "{% if env == 'prod' %} '--no-dev --optimize-autoloader --no-interaction' {% else %} '' {% endif %}"
- debug: var=composer_opts
Exemplo de saída:
sudo ansible-playbook test.yml -e env=dev
PLAY [127.0.0.1] **************************************************************
GATHERING FACTS ***************************************************************
ok: [127.0.0.1]
TASK: [set_fact ] *************************************************************
ok: [127.0.0.1]
TASK: [debug var="{{composer_opts}}"] *****************************************
ok: [127.0.0.1] => {
"var": {
" '' ": " '' "
}
}
PLAY RECAP ********************************************************************
127.0.0.1 : ok=3 changed=0 unreachable=0 failed=0
sudo ansible-playbook test.yml -e env=prod
PLAY [127.0.0.1] **************************************************************
GATHERING FACTS ***************************************************************
ok: [127.0.0.1]
TASK: [set_fact ] *************************************************************
ok: [127.0.0.1]
TASK: [debug var="{{composer_opts}}"] *****************************************
ok: [127.0.0.1] => {
"var": {
" '--no-dev --optimize-autoloader --no-interaction' ": " '--no-dev --optimize-autoloader --no-interaction' "
}
}
PLAY RECAP ********************************************************************
127.0.0.1 : ok=3 changed=0 unreachable=0 failed=0