0
votes

I am trying to run a task in ansible playbook as below.

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

I am using macOS and already installed ansible and sshpass. I am able to run different task through ansible on a remote linux machine but when run this group task I am getting error as 'Connection' object has no attribute 'ssh' ansible.

Kindly guide me what could be the issue ?

EDIT: trace back for issue

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'

EDIT:

I was asked to check ansible.cfg file. But i am not able to locate this file on mac.

Below are the logs when i use ansible --version command

ansible 2.7.6

config file = None

configured module search path = [u'/Users/dhiraj/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /Library/Python/2.7/site-packages/ansible executable location = /usr/local/bin/ansible python version = 2.7.10 (default, Jul 15 2017, 17:16:57) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]

1
Please do us a favor and post the actual traceback, since the error message is just the tip of that iceberg. Also, in the future please consider formatting your question sanely, since YAML cares a lot about whitespacemdaniel
Kindly check my updated question. I have added traceback now.TechChain
It would also be polite to indicate that you have already filed an issue, keep people from spinning their wheels: github.com/ansible/ansible/issues/51590 (and also try the ansible.cfg change from the comments)mdaniel

1 Answers

0
votes

I have solved issue by doing steps

Created a .ansible.cfg file by using content from this link & placed that file in my home directory i.e.

/Users/username/.ansible.cfg

I added in the .ansible.cfg file

[defaults]

transport = ssh

I added Path of .ansible.cfg in ANSIBLE_CONFIG environment variable

I exported this as export ANSIBLE _CONFIG=$HOME/.ansible.cfg in .bash_profile

after doing all these steps i was able to run the playbook.