Roots Discourse

Can't deploy to Kinsta using Trellis. 'AnsibleUnicode' object has no attribute 'get_groups'

I have followed the guide by @benword on https://kinsta.com/blog/bedrock-trellis/
I have tried different python/ansible configurations to no avail. I have the latest Trellis changes.

[WARNING]: Failure using method (v2_playbook_on_play_start) in callback plugin (<ansible.plugins.callback.vars.CallbackModule object at 0x10ecae970>): ‘AnsibleUnicode’ object has no attribute ‘get_groups’

Callback Exception:
File “/.pyenv/versions/2.7.18/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py”, line 333, in send_callback
method(*new_args, **kwargs)
File “/trellis/lib/trellis/plugins/callback/vars.py”, line 103, in v2_playbook_on_play_start
hostvars = play.get_variable_manager().get_vars(play=play, host=host)
File “/.pyenv/versions/2.7.18/lib/python2.7/site-packages/ansible/vars/manager.py”, line 205, in get_vars
host_groups = sort_groups([g for g in host.get_groups() if g.name not in [‘all’]])

After that I get a bunch of skipped tasks:

skipping: no hosts matched
skipping: [kinsta_staging] => {
"changed": false,
"skip_reason": "Conditional result was False"}

etc.
Ending with:

kinsta_staging : ok=2 changed=0 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0

I am using:

ansible 2.9.2
config file = /Users/myusername/Desktop/bedrock_site/my_site/trellis/ansible.cfg
configured module search path = [’/Users/myusername/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.9.6 (default, Jun 29 2021, 06:20:32) [Clang 12.0.0 (clang-1200.0.32.29)]

My wordpress_sites.yml file looks like this:

wordpress_sites:
my_site:
site_hosts:

  • canonical: staging.my_site
    redirects:
  • www.staging.my_site
    local_path: …/site
    branch: master
    repo: myrepo…
    repo_subtree_path: site
    multisite:
    enabled: false
    ssl:
    enabled: false
    provider: letsencrypt
    cache:
    enabled: false

My hosts/staging looks like:

kinsta_staging ansible_host=ip_address ansible_ssh_port=my_port ansible_ssh_extra_args=’-o StrictHostKeyChecking=no’
[staging]
kinsta_staging
[web]
kinsta_staging

I have validated all .yml files using a validator.
Anyone have any idea what is the issue? I’ve spent so much time trying to figure it out.

This can happen when quotes are accidentally omitted. Is the path …/site used like this or only an example? It got three dots, not just two.

Just two. Not sure why I added an extra dot there, but I checked the file and it is correct.

How are you invoking ansible to apply the playbook?
This looks to me as if ansible isn’t able to find a set of variables - wrong/missing environment maybe?

ansible-playbook deploy.yml -e env=staging -e site=my_site --limit=kinsta_staging

I haven’t modified the deploy.yml file. I simply followed the guide I posted and have double checked that.

I have managed to fix a problem. My web_user was set as example in trellis/group_vars/staging/main.yml. Once I corrected it to {my_user} I was able to progress further in the deployment.
Now I am getting the following error:

TASK [deploy : Initialize] ******************************************************************************************************************************************************************************************************
task path: /Users/{my_name}/Desktop/{site_folder}/{my_site}/trellis/roles/deploy/tasks/initialize.yml:16
Using module file /Users/{my_name}/Desktop/{site_folder}/a210p396/lib/python3.9/site-packages/ansible/modules/web_infrastructure/deploy_helper.py
Pipelining is enabled.
<{staging_ip}> ESTABLISH SSH CONNECTION FOR USER: {my_user}
<{staging_ip}> SSH: EXEC ssh -o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=41584 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ‘User="{my_user}"’ -o ConnectTimeout=10 -o HostKeyAlgorithms=ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,ssh-rsa -o ControlPath=/Users/{my_name}/.ansible/cp/b77ed27891 {staging_ip} ‘/bin/sh -c ‘"’"’/usr/bin/python && sleep 0’"’"’’
<{staging_ip}> (1, b’’, b’Traceback (most recent call last):\n File “”, line 102, in \n File “”, line 94, in _ansiballz_main\n File “”, line 40, in invoke_module\n File “/usr/lib/python2.7/runpy.py”, line 188, in run_module\n fname, loader, pkg_name)\n File “/usr/lib/python2.7/runpy.py”, line 82, in _run_module_code\n mod_name, mod_fname, mod_loader, pkg_name)\n File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code\n exec code in run_globals\n File “/tmp/ansible_deploy_helper_payload_TJb5QS/ansible_deploy_helper_payload.zip/ansible/modules/web_infrastructure/deploy_helper.py”, line 521, in \n File “/tmp/ansible_deploy_helper_payload_TJb5QS/ansible_deploy_helper_payload.zip/ansible/modules/web_infrastructure/deploy_helper.py”, line 482, in main\n File “/tmp/ansible_deploy_helper_payload_TJb5QS/ansible_deploy_helper_payload.zip/ansible/modules/web_infrastructure/deploy_helper.py”, line 344, in create_path\n File “/usr/lib/python2.7/os.py”, line 150, in makedirs\n makedirs(head, mode)\n File “/usr/lib/python2.7/os.py”, line 157, in makedirs\n mkdir(name, mode)\nOSError: [Errno 13] Permission denied: ‘/www/{my_user}_123’\n’)
<{staging_ip}> Failed to connect to the host via ssh: Traceback (most recent call last):
File “”, line 102, in
File “”, line 94, in _ansiballz_main
File “”, line 40, in invoke_module
File “/usr/lib/python2.7/runpy.py”, line 188, in run_module
fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/tmp/ansible_deploy_helper_payload_TJb5QS/ansible_deploy_helper_payload.zip/ansible/modules/web_infrastructure/deploy_helper.py”, line 521, in
File “/tmp/ansible_deploy_helper_payload_TJb5QS/ansible_deploy_helper_payload.zip/ansible/modules/web_infrastructure/deploy_helper.py”, line 482, in main
File “/tmp/ansible_deploy_helper_payload_TJb5QS/ansible_deploy_helper_payload.zip/ansible/modules/web_infrastructure/deploy_helper.py”, line 344, in create_path
File “/usr/lib/python2.7/os.py”, line 150, in makedirs
makedirs(head, mode)
File “/usr/lib/python2.7/os.py”, line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: ‘/www/{my_user}_123’

I can ssh in using the same user, ip, and port from the machine I am deploying from.
I am deploying into a fresh staging site.
Also, if I ssh in as the same user I am able to create directories in the command line.


Not sure if this is helpful, bu these are the results of the previous Tasks:

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 0x10a8082b0>): ‘AnsibleUnicode’ object has no attribute ‘get_groups’
skipping: no hosts matched
PLAY [Test Connection] ********************************************************************************************
META: ran handlers
TASK [connection : Require manual definition of remote-user] ********************************************************************************************
skipping: [kinsta_staging] => {
“changed”: false,
“skip_reason”: “Conditional result was False”
}
TASK [connection : Specify preferred HostKeyAlgorithms for unknown hosts] ********************************************************************************************
ok: [kinsta_staging]
TASK [connection : Check whether Ansible can connect as ueymx] ********************************************************************************************
ok: [kinsta_staging -> localhost]
TASK [connection : Warn about change in host keys] ********************************************************************************************
skipping: [kinsta_staging] => {
“changed”: false,
“skip_reason”: “Conditional result was False”
}
TASK [connection : Set remote user for each host] ********************************************************************************************
skipping: [kinsta_staging] => {
“changed”: false,
“skip_reason”: “Conditional result was False”
}
TASK [connection : Announce which user was selected] ********************************************************************************************
skipping: [kinsta_staging] => {}
TASK [connection : Load become password] ********************************************************************************************
skipping: [kinsta_staging] => {
“censored”: “the output has been hidden due to the fact that ‘no_log: true’ was specified for this result”,
“changed”: false
}
PLAY [Deploy WP site] ********************************************************************************************
TASK [Gathering Facts] ********************************************************************************************
ok: [kinsta_staging]
TASK [Ensure site is valid] ********************************************************************************************
skipping: [kinsta_staging] => {
“changed”: false,
“skip_reason”: “Conditional result was False”
}
TASK [Ensure repo is valid] ********************************************************************************************
skipping: [kinsta_staging] => {
“changed”: false,
“skip_reason”: “Conditional result was False”
}
TASK [deploy : Check if deploy_before scripts exist] ********************************************************************************************
TASK [deploy : include_tasks] ********************************************************************************************
TASK [deploy : Check if deploy_initialize_before scripts exist] ********************************************************************************************
TASK [deploy : include_tasks] ********************************************************************************************

It looks as ansible tries to literally use the username {my_user}. You haven’t redacted this (e.g. a sensitive user name you don’t want to publish) in the logs you posted here, right?

Yes I redacted the info.

From the log, seems both python v2 and v3 are used at the same time.

Can you try deploying via trellis-cli?

# After installing trellis-cli
cd /path/to/trellis
trellis init
trellis galaxy install
trellis deploy staging my_site

It probably won’t reslove all the issues but it helps eliminate issues with python versions.


TASK [deploy : Check if deploy_initialize_before scripts exist]

OSError: [Errno 13] Permission denied: ‘/www/{my_user}_123’

Do you have any custom tasks in the deploy_initialize_before hook (or any deploy hooks)?


What are these variables in group_var for staging?

  • www_root
  • project_root

(If they are not specified in group_vars/staging, they are inherited from group_vars/all)


If you need an example, go to https://github.com/ItinerisLtd/trellis-kinsta-template and then:

  1. search xxx in all files
  2. compare it to https://github.com/roots/trellis