2

I'm trying to power cycle a machine using ansible's ipmi_power module.

The documentation says you need to have pyghmi installed on the host where you are executing the playbook, and I've confirmed I have the module for both python 2 & 3.

[userg@box ~]$ python3
Python 3.6.8 (default, Apr  2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyghmi.ipmi
>>> quit()

[user@box ~]$ python
Python 2.7.5 (default, Apr  2 2020, 13:16:51)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyghmi.ipmi
>>> quit()

I have a role called power_cycle and it is defined like this:

---
- name: "powering down {{ ansible_hostname }}"
  ipmi_power:
    name: "{{ ansible_hostname }}"
    user: "{{ ipmi_user }}"
    password: "{{ ipmi_password }}"
    state: off

And I have a playbook that invokes the role, it looks like this:

---
- name: power cycle
  hosts: boxes

  roles:
    - power_cycle

When I run the playbook, I get an error message:

$ ansible-playbook --limit target_box playbooks/power_cycle.yml

PLAY [power cycle]********************************************************************************

TASK [Gathering Facts] ***************************************************************************
ok: [target_box]

TASK [power_cycle : powering down target_box]*****************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named pyghmi.ipmi
fatal: [target_box]: FAILED! => changed=false 
  exception: |-
    Traceback (most recent call last):
      File "/tmp/ansible_ipmi_power_payload_skn3T3/ansible_ipmi_power_payload.zip/ansible/modules/remote_management/ipmi/ipmi_power.py", line 81, in <module>
    ImportError: No module named pyghmi.ipmi
    msg: Failed to import the required Python library (pyghmi) on target_box's Python 
    /usr/bin/python. Please read module documentation and install in the appropriate location. If the 
    required library is installed, but Ansible is using the wrong Python interpreter, please consult 
    the documentation on ansible_python_interpreter

PLAY RECAP***************************************************************************************
target_box : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0  

The error message seems to be suggesting I have to have pyghmi installed on the machine I'm trying to manage via IPMI. This seems to contradict the documentation for the ipmi_power module.

What am I doing wrong?

2

I went digging through issues on ansible's github.

I found an issue with the ipmi_power that had an example of how to use it. You need to use the delegate_to property on the task to ensure it runs locally.

Changing my role definition to this worked:

---
- name: "powering down {{ ansible_hostname }}"
  ipmi_power:
    name: "{{ ansible_hostname }}"
    user: "{{ ipmi_user }}"
    password: "{{ ipmi_password }}"
    state: off
  delegate_to: localhost
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.