Re: [ansible-project] Using multiple variables with Assert

165 views
Skip to first unread message
Message has been deleted

Will McDonald

unread,
Oct 10, 2023, 1:01:35 PM10/10/23
to ansible...@googlegroups.com
I think you want "in" rather than "==" to verify if your OS release is in the corresponding list.

On Tue, 10 Oct 2023, 17:51 Veera, <svee...@gmail.com> wrote:
Hi,

I am trying with the first task of the playbook with assert module to validate the supported versions. If Assert is success, then only the next tasks will be executed .

- name: Playbook to test the conditional
  hosts: localhost
  vars:
     rhel_ver:
       - 9
       - 8
       - 7
    centos_ver:
        - 8
        - 7  
  tasks:
      - name: Check the OS version and proceed based on the OS
        ansible.builtin.assert:
            that:
                - ansible_distribution == "CentOS" and ansible_distribution_major_version == "{{ centos_ver }}"
                - ansible_distribution == "RedHat" and ansible_distribution_major_version == "{{ rhel_ver }}"
           fail_msg: "Unsupported OS version. Exiting ..... "
           success_msg: "Supported OS version and proceeding to next task"
   
       - debug:
     msg: "Completed"

The Asset have to be Success with multiple conditions .. If either the distribution is RedHat or CentOS(not both conditions need to be true)  and the major version is atleast one of the value from the variables(of its OS distro). 



 



--
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/c2457c47-2460-47d4-86d0-4e872f7c5dd9n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages