disable_service_controls is not working

8 views
Skip to first unread message

Vishwas Govekar

unread,
Jun 6, 2020, 8:41:06 PM6/6/20
to Ansible Project
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

Abhijeet Kasurde

unread,
Jun 6, 2020, 11:16:12 PM6/6/20
to ansible...@googlegroups.com
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.

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bb85054d-d318-4033-b1b8-249f69c17df7o%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Vladimir Botka

unread,
Jun 6, 2020, 11:45:16 PM6/6/20
to Vishwas Govekar, ansible...@googlegroups.com
On Sat, 6 Jun 2020 17:41:05 -0700 (PDT)
Vishwas Govekar <govekar...@gmail.com> wrote:

> 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

shell> 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.

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

HTH,

-vlado

--
Vladimir Botka

Vladimir Botka

unread,
Jun 7, 2020, 2:33:39 PM6/7/20
to Vishwas Govekar, ansible...@googlegroups.com

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

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

On Sun, 7 Jun 2020 12:29:48 -0400
Vishwas Govekar <govekar...@gmail.com> wrote:
> 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
--
Reply all
Reply to author
Forward
0 new messages