---
- name: Converge file for system_attributes
  hosts: all
  gather_facts: false
  vars:
    hostname: "{{ lookup('env', 'IDRAC_IP') }}"
    username: "{{ lookup('env', 'IDRAC_USER') }}"
    password: "{{ lookup('env', 'IDRAC_PASSWORD') }}"
    validate_certs: false
  roles:
    - role: idrac_attributes
      vars:
        system_attributes:
          ServerOS.1.HostName: demohostname
  tasks:
    - name: Asserting system_attributes update in check mode
      ansible.builtin.assert:
        that: idrac_attributes_out.msg == "Changes found to be applied."
      when: ansible_check_mode
      tags: molecule-idempotence-notest

    - name: Asserting system_attributes update in normal mode
      ansible.builtin.assert:
        that:
          - idrac_attributes_out.msg == "Successfully updated the attributes."
      when: not ansible_check_mode and idrac_attributes_out.changed

    - name: Asserting system_attributes update in idempotence mode
      ansible.builtin.assert:
        that:
          - idrac_attributes_out.msg == "No changes found to be applied."
      when: not ansible_check_mode and not idrac_attributes_out.changed
