Hi all, im trying to use a 'complex' expression to evaluate if a task should run as root or not.
Here is what i have defined: ``` debian_based_system: ansible_os_family == 'Debian' or ansible_os_family == 'Linuxmint' ``` My tasks look like this ``` - debug: var=ansible_os_family - debug: var={{ debian_based_system }} - debug: var=debian_based_system - shell: echo $EUID args: executable: /bin/bash become: "{{ debian_based_system }}" - shell: echo $EUID args: executable: /bin/bash become: true - shell: echo $EUID args: executable: /bin/bash become: debian_based_system ``` and when i run them, i get ``` TASK [test : debug] ********************************************************************************************************************************************************************************************************************************************************* ok: [localhost] => { "ansible_os_family": "Linuxmint" } TASK [test : debug] ********************************************************************************************************************************************************************************************************************************************************* ok: [localhost] => { "ansible_os_family == 'Debian' or ansible_os_family == 'Linuxmint'": true } TASK [test : debug] ********************************************************************************************************************************************************************************************************************************************************* ok: [localhost] => { "debian_based_system": "ansible_os_family == 'Debian' or ansible_os_family == 'Linuxmint'" } TASK [test : command] ******************************************************************************************************************************************************************************************************************************************************* changed: [localhost] => {"changed": true, "cmd": "echo $EUID", "delta": "0:00:00.003180", "end": "2017-12-13 11:48:16.830302", "rc": 0, "start": "2017-12-13 11:48:16.827122", "stderr": "", "stderr_lines": [], "stdout": "1000", "stdout_lines": ["1000"]} TASK [test : command] ******************************************************************************************************************************************************************************************************************************************************* changed: [localhost] => {"changed": true, "cmd": "echo $EUID", "delta": "0:00:00.002833", "end": "2017-12-13 11:48:16.988274", "rc": 0, "start": "2017-12-13 11:48:16.985441", "stderr": "", "stderr_lines": [], "stdout": "0", "stdout_lines": ["0"]} TASK [test : command] ******************************************************************************************************************************************************************************************************************************************************* changed: [localhost] => {"changed": true, "cmd": "echo $EUID", "delta": "0:00:00.002869", "end": "2017-12-13 11:48:17.143074", "rc": 0, "start": "2017-12-13 11:48:17.140205", "stderr": "", "stderr_lines": [], "stdout": "1000", "stdout_lines": ["1000"]} ``` which means that only `become: true` gave my task sudo access (and not any of the other two). If i change the definition to `debian_based_system: '{{ ansible_os_family == "Debian" or ansible_os_family == "Linuxmint" }}'`, then i get correct results for the first two shell tasks but i also get a warning about using {{ }} in when statements. ``` TASK [test : debug] ********************************************************************************************************************************************************************************************************************************************************* [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ ansible_os_family == "Debian" or ansible_os_family == "Linuxmint" }} ok: [localhost] => { "ansible_os_family": "Linuxmint" } TASK [test : debug] ********************************************************************************************************************************************************************************************************************************************************* [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ ansible_os_family == "Debian" or ansible_os_family == "Linuxmint" }} ok: [localhost] => { "true": "VARIABLE IS NOT DEFINED!" } TASK [test : debug] ********************************************************************************************************************************************************************************************************************************************************* [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ ansible_os_family == "Debian" or ansible_os_family == "Linuxmint" }} ok: [localhost] => { "debian_based_system": true } TASK [test : command] ******************************************************************************************************************************************************************************************************************************************************* [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ ansible_os_family == "Debian" or ansible_os_family == "Linuxmint" }} changed: [localhost] => {"changed": true, "cmd": "echo $EUID", "delta": "0:00:00.002737", "end": "2017-12-13 11:51:29.057079", "rc": 0, "start": "2017-12-13 11:51:29.054342", "stderr": "", "stderr_lines": [], "stdout": "0", "stdout_lines": ["0"]} TASK [test : command] ******************************************************************************************************************************************************************************************************************************************************* [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ ansible_os_family == "Debian" or ansible_os_family == "Linuxmint" }} changed: [localhost] => {"changed": true, "cmd": "echo $EUID", "delta": "0:00:00.003077", "end": "2017-12-13 11:51:29.227123", "rc": 0, "start": "2017-12-13 11:51:29.224046", "stderr": "", "stderr_lines": [], "stdout": "0", "stdout_lines": ["0"]} TASK [test : command] ******************************************************************************************************************************************************************************************************************************************************* [WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ ansible_os_family == "Debian" or ansible_os_family == "Linuxmint" }} changed: [localhost] => {"changed": true, "cmd": "echo $EUID", "delta": "0:00:00.003351", "end": "2017-12-13 11:51:29.386325", "rc": 0, "start": "2017-12-13 11:51:29.382974", "stderr": "", "stderr_lines": [], "stdout": "1000", "stdout_lines": ["1000"]} ``` What is the correct way to define this so that it works and i dont get the warning ? Cheers, Mike ``` $ ansible --version ansible 2.3.1.0 config file = configured module search path = Default w/o overrides python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609] ``` -- 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-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8bdc5b98-4405-408a-b552-e8b3729a7016%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.