Provisioning server not working because ‘ansible_ssh_extra_args’ is undefined

(macOS Catalina 19.15.7)
I’m getting the same error as https://discourse.roots.io/t/provisioning-server-not-working-because-ansible-ssh-extra-args-is-undefined/17484

I upgraded ansible :

ansible --version
ansible [core 2.11.1] 
  config file = /Users/***/Desktop/example.com/trellis/ansible.cfg
  configured module search path = ['/Users/***/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/***/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.5 (default, May  4 2021, 03:33:11) [Clang 12.0.0 (clang-1200.0.32.29)]
  jinja version = 3.0.1
  libyaml = True 

Still having the error,
I tried changing line 15 in trellis/hosts/roles/connection/tasks/main.yml
from

  • not ansible_ssh_extra_args
    to
  • not (not ansible_ssh_extra_args)
    after reading this
    but still getting the error
trellis git:(master) ✗ ansible-playbook server.yml -e env=production
[WARNING]: Your Ansible version is 2.11.1 but this version of Trellis has only been tested for compatability with Ansible 2.8.0 ->
2.9.10. It is advisable to check for Trellis updates or downgrade your Ansible version.

PLAY [Ensure necessary variables are defined] *************************************************************************************
[WARNING]: Failure using method (v2_playbook_on_play_start) in callback plugin (<ansible.plugins.callback.vars.CallbackModule
object at 0x104f23580>): 'PlayContext' object has no attribute '_ssh_args'

TASK [Ensure environment is defined] **********************************************************************************************
skipping: [localhost]

PLAY [Test Connection and Determine Remote User] **********************************************************************************

TASK [connection : Require manual definition of remote-user] **********************************************************************
skipping: [142.93.104.120]

TASK [connection : Specify preferred HostKeyAlgorithms for unknown hosts] *********************************************************
System info:
  Ansible 2.11.1; Darwin
  Trellis version (per changelog): "Fix #1284 - Update logrotate postrotate Nginx command"
---------------------------------------------------
The conditional check 'not (not ansible_ssh_extra_args)' failed. The error
was: error while evaluating conditional (not (not ansible_ssh_extra_args)):
'ansible_ssh_extra_args' is undefined

The error appears to be in '/Users/***/Desktop/example.com/trellis/
roles/connection/tasks/main.yml': line 9, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: Specify preferred HostKeyAlgorithms for unknown hosts
  ^ here
fatal: [142.93.104.120]: FAILED! => {}

PLAY RECAP ************************************************************************************************************************
142.93.104.120             : ok=0    changed=0    unreachable=0    failed=1    skipped=1    rescued=0    ignored=0   
localhost                  : ok=0    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0 

As I got this warning
[WARNING]: Your Ansible version is 2.11.1 but this version of Trellis has only been tested for compatability with Ansible 2.8.0 ->
2.9.10. It is advisable to check for Trellis updates or downgrade your Ansible version.
I tried to downgrade ansible

sudo python3 -m pip install ansible==2.9.10 

That gives me the message

Successfully installed ansible-2.9.10

However when I run ansible --version I get

ansible --version
ERROR! Unexpected Exception, this is probably a bug: cannot import name 'AnsibleCollectionLoader' from 'ansible.utils.collection_loader' (/usr/local/lib/python3.9/site-packages/ansible/utils/collection_loader/__init__.py)
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible", line 92, in <module>
    mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]), myclass)
  File "/usr/local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 22, in <module>
    from ansible.inventory.manager import InventoryManager
  File "/usr/local/lib/python3.9/site-packages/ansible/inventory/manager.py", line 38, in <module>
    from ansible.plugins.loader import inventory_loader
  File "/usr/local/lib/python3.9/site-packages/ansible/plugins/loader.py", line 26, in <module>
    from ansible.utils.collection_loader import AnsibleCollectionLoader, AnsibleFlatMapLoader, AnsibleCollectionRef
ImportError: cannot import name 'AnsibleCollectionLoader' from 'ansible.utils.collection_loader' (/usr/local/lib/python3.9/site-packages/ansible/utils/collection_loader/__init__.py)

I tried to uninstall and reinstall ansible both with brew and pip, at this point I don’t know where I’m doing something wrong with trellis or with the installation of ansible.
Any suggestions?

Finally! After hours of jumping from one thread to another here’s what solved it for me.
and adding this to .zshrc

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi
alias pip=/usr/local/bin/pip3

Edit: Forgot to mention the most important, I had to install ansible 2.10.10 to get it to work.
following this

3 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.