disable_service_controls is not working

Hi

I have ansible roles for each app which has stop and start tasks ,I have global role deploy_all which use stop all ,deploy apps in sequential order and start all
When I call the global role deploy_all the local start and stop should not work .I have passed the when: “{{ disable_service_controls | default(false) }}” == false in start.yml But it is failing
Anys suggestions how to fix it

Hi Vishwas,

Without looking at logs and playbooks used, it is very difficult to tell what is wrong. Please provide details about background, roles used, a snippet of playbook failing, console log of the run, debugging steps taken, etc.

  when: "{{ disable_service_controls|
            default(false) }}" == false

See "The When Statement"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#the-when-statement
" ... which contains a raw Jinja2 expression without double curly braces."

Try this playbook

  > cat pb.yml
  - hosts: localhost
    tasks:
      - debug:
          msg: Disabled
        when: disable_service_controls|
              default(false)|
              bool
      - set_fact:
          disable_service_controls: true
      - debug:
          msg: Disabled
        when: disable_service_controls|
              default(false)|
              bool

It will skip the first debug. (Gives abridged)

  TASK [debug] ****
  skipping: [localhost]
  TASK [set_fact] ****
  ok: [localhost]
  TASK [debug] ****
  ok: [localhost] => { "msg": "Disabled" }

Use "bool" filters. See "Bare variables in conditionals"
https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_2.8.html#bare-variables-in-conditionals
" ... update your conditional statements so they accept only boolean values."

In addition to this, try --extra-vars. Extra vars pass the values always as
strings. The explicit conversion to boolean is necessary.

  > ansible-playbook pb.yml -e "disable_service_controls=true"

HTH,

  -vlado

> > when: "{{ disable_service_controls|
> > default(false) }}" == false

> when: disable_service_controls|
> default(false)|
> bool

Does the script look good
[...]
      when: "disable_service_controls is not defined or
             disable_service_controls == false"

No. It does not. This one (in the previous email) looks good

        when: disable_service_controls|
              default(false)|
              bool