我会使用 ipaddr 过滤器检查输入的 mac_address 语法,这需要 netaddr python 包才能使用它。 netaddr 已安装在我的控制器中
Requirement already satisfied: netaddr in /usr/lib/python3.6/site-packages (0.7.19)
但是当我运行剧本时,我得到的是
---
- name: test MAC address manipulation
hosts: all
strategy: free
gather_facts: no
connection: local
no_log: false
# vars_prompt:
# - name: "macaddress"
# prompt: "mac address?"
# private: no
vars:
macaddress: "1a-2b-3c-4d-5e-6f"
tasks:
- name: display all the formats
ignore_errors: true
debug:
msg:
- Original = {{ macaddress }}
- ""
- "{ macaddress | ansible.utils.hwaddr('bool') } = {{ macaddress | ansible.utils.hwaddr('bool') }}"
剧本执行
*
fatal: [Control]: FAILED! => {"msg": "The hwaddr filter requires python's netaddr be installed on the ansible controller"}
...ignoring
fatal: [Ansible1]: FAILED! => {"msg": "The hwaddr filter requires python's netaddr be installed on the ansible controller"}
...ignoring
fatal: [Ansible2]: FAILED! => {"msg": "The hwaddr filter requires python's netaddr be installed on the ansible controller"}
...ignoring
fatal: [Tower]: FAILED! => {"msg": "The hwaddr filter requires python's netaddr be installed on the ansible controller"}
...ignoring
fatal: [ansible3]: FAILED! => {"msg": "The hwaddr filter requires python's netaddr be installed on the ansible controller"}
...ignoring
fatal: [Ubuntu]: FAILED! => {"msg": "The hwaddr filter requires python's netaddr be installed on the ansible controller"}
...ignoring
PLAY RECAP *******************************************************************************************************************
Ansible1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1
Ansible2 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1
Control : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1
Tower : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1
Ubuntu : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1
ansible3 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1
这是ansible和python版本
ansible [core 2.12.5]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.8/site-packages/ansible
ansible collection location = /home/x/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
jinja version = 2.10.3
libyaml = True
您已在 python3.6 库中的控制器上安装了 netaddr,但您的 Ansible 使用的是 python3.8。
python3.8 -m pip install netaddr
或者使用 virtualenv。