---
- name: "Configure {{ inventory_hostname }} power state"
  vars:
    # Create an anchor for api_info that can be used throughout the file
    api_info: &api_info
      api_private_key: "{{ api_private_key }}"
      api_key_id: "{{ api_key_id }}"
      api_uri: "{{ api_uri | default(omit) }}"
      validate_certs: "{{ validate_certs | default(omit) }}"
      state: "{{ state | default(omit) }}"
  cisco.intersight.intersight_rest_api:
    <<: *api_info
    resource_path: /compute/ServerSettings
    query_params:
      $filter: "Server.Moid eq '{{ server_moid }}'"
    api_body: {
      "AdminPowerState": "{{ power_state }}"
    }
  when: power_state is defined
# Configure LED locator state
- name: "Configure {{ inventory_hostname }} locator state"
  cisco.intersight.intersight_rest_api:
    <<: *api_info
    resource_path: /compute/ServerSettings
    query_params:
      $filter: "Server.Moid eq '{{ server_moid }}'"
    api_body: {
      "AdminLocatorLedState": "{{ locator_state }}"
    }
  when: locator_state is defined
