register and looping

i am trying to use “ipmitools” to check power status and based on the result i will start/reset the server.But i am not able to continue as register: and looping are not working .Is there any alternate approach for achieving below?


  • hosts: compute
    gather_facts: no
    vars_files:
  • input.yml

tasks:

  • name: check Power status of target
    local_action: command ipmitool -I lanplus -H {{item.console}} -U {{item.consoleuser}} -P {{item.consolepassword}} power status
    with_items:

  • “{{ computeserver1 }}”
    when: item.console and item.consoleuser and item.consolepassword is defined
    register: power

  • name: check Debug
    debug: var=power.stdout

  • name: Power Reset
    local_action: command ipmitool -I lanplus -H {{item.console}} -U {{item.consoleuser}} -P {{item.consolepassword}} power reset
    with_items:

  • “{{ computeserver1 }}”
    when: item.console and item.consoleuser and item.consolepassword is defined and power.stdout.find(‘Chassis Power is on’) != -1

  • name: Power On
    local_action: command ipmitool -I lanplus -H {{item.console}} -U {{item.consoleuser}} -P {{item.consolepassword}} power on
    with_items:

  • “{{ computeserver1 }}”
    when: item.console and item.consoleuser and item.consolepassword is defined and power.stdout.find(‘Chassis Power is off’) != -1

Thanks for any help

Can you share the structure of the “computeserver1” or even better the content of the input.yml file?

I guess you have confirmed that executing the same ipmi command from the Ansible station manually works properly?

contents of input.yml

Ok wrote this simple playbook just to test it: