'Connection' 对象在 macOS 上没有属性 'ssh' ansible?

'Connection' object has no attribute 'ssh' ansible on macOS?

我正在尝试 运行 ansible 剧本中的一项任务,如下所示。

- name: Add user to a group
      user:
        name: "{{ansible_user}}"
        groups: docker
        append: yes
      become: yes
      when: node_type == "peer"

我正在使用 macOS 并且已经安装了 ansible 和 sshpass。我可以通过远程 linux machine 上的 ansible 运行 不同的任务,但是当 运行 这个组任务时,我收到错误 'Connection' object has no attribute 'ssh' ansible.

请指导我可能是什么问题?

编辑: 追溯问题

ERROR! Unexpected Exception, this is probably a bug: 'Connection' object has no attribute 'ssh'
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook", line 118, in <module>
    exit_code = cli.run()
  File "/Library/Python/2.7/site-packages/ansible/cli/playbook.py", line 122, in run
    results = pbex.run()
  File "/Library/Python/2.7/site-packages/ansible/executor/playbook_executor.py", line 156, in run
    result = self._tqm.run(play=play)
  File "/Library/Python/2.7/site-packages/ansible/executor/task_queue_manager.py", line 291, in run
    play_return = strategy.run(iterator, play_context)
  File "/Library/Python/2.7/site-packages/ansible/plugins/strategy/linear.py", line 267, in run
    results.extend(self._execute_meta(task, play_context, iterator, host))
  File "/Library/Python/2.7/site-packages/ansible/plugins/strategy/__init__.py", line 1098, in _execute_meta
    connection.reset()
  File "/Library/Python/2.7/site-packages/ansible/plugins/connection/paramiko_ssh.py", line 539, in reset
    self.close()
  File "/Library/Python/2.7/site-packages/ansible/plugins/connection/paramiko_ssh.py", line 606, in close
    self.ssh.close()
AttributeError: 'Connection' object has no attribute 'ssh'

编辑:

我被要求检查 ansible.cfg 文件。但我无法在 mac.

上找到此文件

下面是我使用ansible --version命令时的日志

ansible 2.7.6

config file = None

配置的模块搜索路径=[u'/Users/dhiraj/.ansible/plugins/modules',u'/usr/share/ansible/plugins/modules'] ansible python 模块位置 = /Library/Python/2.7/site-packages/ansible 可执行位置= /usr/local/bin/ansible python 版本 = 2.7.10(默认,2017 年 7 月 15 日,17:16:57)[GCC 4.2.1 兼容 Apple LLVM 9.0.0 (clang-900.0.31)]

我已经通过执行步骤解决了问题

使用此 link 中的内容创建了一个 .ansible.cfg 文件,并将该文件放在我的主目录中,即

/Users/username/.ansible.cfg

我在 .ansible.cfg 文件中添加了

[默认值]

transport = ssh

我在ANSIBLE_CONFIG环境变量

中添加了.ansible.cfg的路径

我将其导出为 export ANSIBLE _CONFIG=$HOME/.ansible.cfg in .bash_profile

完成所有这些步骤后,我能够运行剧本。