我正在尝试使用 ansible 来关闭机器的电源ipmi_电源模块。
文档说你需要皮格米人安装在您执行剧本的主机上,并且我已确认我拥有 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()
我有一个名为的角色power_cycle
,它的定义如下:
---
- name: "powering down {{ ansible_hostname }}"
ipmi_power:
name: "{{ ansible_hostname }}"
user: "{{ ipmi_user }}"
password: "{{ ipmi_password }}"
state: off
我有一个调用该角色的剧本,它看起来像这样:
---
- name: power cycle
hosts: boxes
roles:
- power_cycle
当我运行剧本时,收到一条错误消息:
$ 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
错误消息似乎暗示我必须在pyghmi
尝试通过 IPMI 管理的机器上安装。这似乎与ipmi_power
模块的文档相矛盾。
我究竟做错了什么?
答案1
我深入研究了 ansible 的 github 上的问题。
我发现一个问题ipmi_电源其中有一个如何使用它的示例。您需要delegate_to
在任务上使用该属性来确保它在本地运行。
将我的角色定义更改为以下有效:
---
- name: "powering down {{ ansible_hostname }}"
ipmi_power:
name: "{{ ansible_hostname }}"
user: "{{ ipmi_user }}"
password: "{{ ipmi_password }}"
state: off
delegate_to: localhost