mac 安装 ansible

mac 安装 ansible

正常pip3安装报错

# 报错版本
#ansible -  --version   
ansible [core 2.12.1]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/Users/apple/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/apple/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.6 (default, Jun 29 2021, 05:25:02) [Clang 12.0.5 (clang-1205.0.22.9)]
  jinja version = 3.0.3
  libyaml = True
#报错内容
#ansible 172.18.154.185 -i hosts/test -m ping -vvv
ansible [core 2.12.1]
  config file = /private/etc/ansible/ansible.cfg
  configured module search path = ['/Users/apple/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/apple/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.6 (default, Jun 29 2021, 05:25:02) [Clang 12.0.5 (clang-1205.0.22.9)]
  jinja version = 3.0.3
  libyaml = True
Using /private/etc/ansible/ansible.cfg as config file
host_list declined parsing /private/etc/ansible/hosts/test as it did not pass its verify_file() method
script declined parsing /private/etc/ansible/hosts/test as it did not pass its verify_file() method
auto declined parsing /private/etc/ansible/hosts/test as it did not pass its verify_file() method
Parsed /private/etc/ansible/hosts/test inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
META: ran handlers
The full traceback is:
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 158, in run
    res = self._execute()
  File "/usr/local/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 532, in _execute
    self._connection = self._get_connection(cvars, templar)
  File "/usr/local/lib/python3.9/site-packages/ansible/executor/task_executor.py", line 916, in _get_connection
    connection, plugin_load_context = self._shared_loader_obj.connection_loader.get_with_context(
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 827, in get_with_context
    self._module_cache[path] = self._load_module_source(name, path)
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 791, in _load_module_source
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/etc/ansible/plugins/connection/sshx.py", line 51, in <module>
    boolean = C.mk_boolean
AttributeError: module 'ansible.constants' has no attribute 'mk_boolean'
172.18.154.185 | FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}

解决方法

卸载原有版本

# pip3 list  

Package            Version
------------------ ---------
ansible-core       2.12.1


# pip3 uninstall  ansible-core  ansible

重新安装指定版本

# pip3 install  ansible==2.10.5 

再次测试正常

# ansible 172.18.154.185 -i hosts/test -m ping     
172.18.154.185 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

posted @ 2022-01-12 09:41  鸣昊  阅读(464)  评论(0编辑  收藏  举报