How to bypass (Conditional is marked as unsafe)

My playbook evaluates in the when clause a variable that is input from Survey on Ansible Automation Platform, but i now i get Conditional is marked as unsafe

code:

task

    - name: Creating user on CentOS7 ( with wheel )
      ansible.builtin.user:
        name: "{{ user }}"
        password: "{{ passwd | password_hash('sha512') }}"
        shell: "{{ user_shell }}"
        append: yes
        state: present
        comment: Created by Ansible
        group: "{{ user }}"
        groups: wheel
      when: ansible_distribution == "CentOS" and "{{ root }}" == "yes"

Reference:
https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_9.html

The condition contains an embedded template ({{ root }}). Bare variables are already templated, so to fix you should remove the brackets and encapsulate the whole conditional in quotation marks:

when: 'ansible_distribution == "CentOS" and root == "yes"'

5 Likes

Thank you, it worked !!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.