---
- hosts: ome
  connection: local
  name: Dell OpenManage Ansible - OME Power state operations.
  gather_facts: False

  collections:
    - dellemc.openmanage

  tasks:
  - name: Power state operation based on device id.
    ome_powerstate:
      hostname:  "{{ hostname }}"
      username: "{{ username }}"
      password:  "{{ password }}"
      device_id: 11111
      power_state: "off"

  - name: Power state operation based on device service tag.
    ome_powerstate:
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
      device_service_tag: "KLBR111"
      power_state: "on"

  - name: Power state operation based on list of device ids.
    ome_powerstate:
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
      device_id: "{{ item.device_id }}"
      power_state: "{{ item.state }}"
    with_items:
      - { "device_id": 11111, "state": "on" }
      - { "device_id": 22222, "state": "off" }

  - name: Power state operation based on list of device service tags.
    ome_powerstate:
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
      device_service_tag: "{{ item.service_tag }}"
      power_state: "{{ item.state }}"
    with_items:
      - { "service_tag": "KLBR111", "state": "on" }
      - { "service_tag": "KLBR222", "state": "off" }