Fresh trellis install - error on vagrant up

I’m having problems running vagrant up on a fresh trellis install, and could do with some advice on how to fix. The error reads:

TASK [common : Validate Ubuntu version] ****************************************

System info:

Ansible 2.7.12; Vagrant 2.2.5; Darwin

Trellis version (per changelog): "Officially support Ubuntu 20.04"

---------------------------------------------------

The conditional check 'ansible_distribution_version is version('18.04', '<')'

failed. The error was: Version comparison: 'ansible_distribution_version' is

undefined

The error appears to have been in '/Users/designlobby/Sites/+trellis/mysite.co.uk/trellis/roles/common/tasks/main.yml': line 67, column 3, but

may

be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Validate Ubuntu version

^ here

fatal: [default]: FAILED! => {}

Many thanks!

So I discovered that there have been two new releases of Trellis in the past week - which for some reason aren’t currently compatible with my setup.

But I did try a fresh install using version 1.5.0 by running:

git clone --depth=1 git@github.com:roots/trellis.git --branch 1.5.0 && rm -rf trellis/.git

And now this also fails with error message:

TASK [composer : Install configured globally-required packages.] ***************
System info:
  Ansible 2.7.12; Vagrant 2.2.5; Darwin
  Trellis 1.5.0: August 5th, 2020
---------------------------------------------------
non-zero return code
Changed current directory to /root/.composer
Do not run Composer as root/super user! See https://getcomposer.org/root for
details


  [RuntimeException]
  No composer.json present in the current directory, this may be the cause of
the following exception.



  [InvalidArgumentException]
  Package hirak/prestissimo at version @stable has a PHP requirement
incompatible with your PHP version, PHP extensions and Composer version


require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--fixed]
[--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-scripts]
[--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-
dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-
platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable]
[--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a
|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix
APCU-AUTOLOADER-PREFIX] [--] [<packages>]...
failed: [default] (item={u'name': u'hirak/prestissimo'}) => {"changed": true, "cmd": ["/usr/local/bin/composer", "global", "require", "hirak/prestissimo:@stable", "--no-progress", "--no-interaction"], "delta": "0:00:00.250289", "end": "2020-11-11 17:25:24.630598", "item": {"name": "hirak/prestissimo"}, "rc": 1, "start": "2020-11-11 17:25:24.380309", "stderr_lines": ["Changed current directory to /root/.composer", "Do not run Composer as root/super user! See https://getcomposer.org/root for details", "", "                                                                                                        ", "  [RuntimeException]                                                                                    ", "  No composer.json present in the current directory, this may be the cause of the following exception.  ", "                                                                                                        ", "", "                                                                                                                                              ", "  [InvalidArgumentException]                                                                                                                  ", "  Package hirak/prestissimo at version @stable has a PHP requirement incompatible with your PHP version, PHP extensions and Composer version  ", "                                                                                                                                              ", "", "require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-scripts] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] [<packages>]..."], "stdout": "", "stdout_lines": []}

Related?:

Hi @strarsis

Yes I saw this post about it Remove prestissimo from composer_global_packages by swalkinshaw · Pull Request #1247 · roots/trellis · GitHub

But I’m not sure how to remove Prestissimo! I tried commenting out in trellis/group_vars/main.yml, but I get a new error:

TASK [composer : include_tasks] ************************************************

System info:

Ansible 2.7.12; Vagrant 2.2.5; Darwin

Trellis 1.5.0: August 5th, 2020

---------------------------------------------------

The conditional check 'composer_global_packages | length > 0' failed. The

error was: Unexpected templating type error occurred on ({% if

composer_global_packages | length > 0 %} True {% else %} False {% endif %}):

object of type 'NoneType' has no len()

The error appears to have been in '/Users/designlobby/Sites/+trellis/mysite

.co.uk/trellis/vendor/roles/composer/tasks/main.yml': line 62, column 3, but

may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- include_tasks: global-require.yml

^ here

I have just found another thread to follow which will hopefully lead to something!

https://discourse.roots.io/t/runtimeexception-no-composer-json-present-in-current-directory/19374/12

Are you using the most recent master of Trellis? Or something older?

In post #1 I was using the most recent version of Trellis and getting the error I posted.

In post #2 I’m trying to get v1.5.0 running as I thought it might help avoid the problems I’m having in 1.7.0.

I’ll happily run 1.7.0 if it will work! And if I can still run my other installs (I have a new trellis environment for each site I work on).

Currently trying to work my way through the other thread I posted above to see if that helps fix anything.

Are you applying the Trellis playbooks on an existing Trellis system?

You can try to fix this on an existing Trellis system by invoking (as root (admin, sudo)):

composer global remove hirak/prestissimo

I’m afraid I don’t know anything about ansible playbooks etc. I have some notes saved on how to get trellis up and running from the first time I managed to get everything working. I only use trellis for local development.

Currently I’m trying to fix this on a trellis 1.5.0 test environment, just so I can get something working before moving to client development sites working.

Where/when would I run composer global remove hirak/prestissimo ? I have tried from my trellis directory after ssh’ing into the server, and from my local trellis directory. Both times I got the error message:

[RuntimeException]                                                                    
  Could not read ./composer.json                                                        
                                                                                        
  file_get_contents(./composer.json): failed to open stream: No such file or directory

I can confirm there is no composer file in my trellis directory.

The Trellis directory (the ansible stuff) doesn’t have to be on the Trellis web server at all.
It has to be on some workstation/ansible runner that uses ansible to connect to the Trellis web server and issue SSH commands to provision it.

The error message shows up for composer v2, and no prestissimo installed.
This means that your Trellis playbook that you are using for provisioning the Trellis web server still tries to do something with composer global commands.
As you wrote about two different Trellis directories, one on your workstation and one on the actual Trellis web server (where it doesn’t need to be and where it shouldn’t actually be), I guess you are applying an outdated Trellis playbook.

Sorry for any confusion, I only have trellis running on my local computer. I still deploy sites manually via SFTP, (only the ‘site’ directory). The ‘trellis’ directory doesn’t touch the production server.

So, I don’t think I’m doing any of the playbook stuff. I’m only trying to get my local Trellis server working. I’m trying to start a clean install, so I don’t mind which trellis version I use as long as something works.

I’ve been trying to follow instructions from the other post on a trellis 1.5.0 install but so far nothing seems to work.

Note that with latest Trellis composer 2 is used, which requires updates of Bedrock projects you want to deploy onto that Trellis server.

How is the Trellis server locally running? Vagrant?

Yes Vagrant. I don’t mind updating Bedrock if necessary, if it’s pretty straight forward.

I only use one Trellis install per site - Scared of having a lot of sites on one Trellis install and then something going wrong! So individual installations for each local site.

Any important files on your vagrant VM - or just as shared folders into the VM?

You can destroy the vagrant VM completely, use the latest Trellis and vagrant up again to get a fresh system.

No, my current attempt is just a test run… happy to destroy and start again.

The only thing is I’m not sure what to do differently as every time I have tried I get errors! :sweat_smile:

OK late in the day but I have 1.5.0 working…

in main.yml

composer_keep_updated: false
composer_version: '1.10.16'
composer_global_packages:
- { name: hirak/prestissimo }

in dev.yml

- { role: composer, tags: [composer], composer_version: '1.10.16', composer_keep_updated: false }

in server.yml

- { role: composer, tags: [composer], composer_version: '1.10.16', composer_keep_updated: false }

When I run vagrant ssh and check the composer version i get Composer version 1.10.16

I’ll test it again in the morning with another fresh install, and deal with the new trellis 1.7.0 another time :sweat_smile:

What about just cloning the whole Trelis repository and then doing vagrant up?

Do you mean cloning it for 1.7.0? I would assume that I’d get my original error from earlier today, but I’ll check that in the morning too.

For now I can sleep knowing that at least 1.5.0 is working with the edits above. :slightly_smiling_face: Thanks for your help today @strarsis

Will report back tomorrow! :grimacing:

Can confirm this is working, both locally and in production, as long as everything is rebuilt - ie running vagrant destroy and vagrant up again was required to force the local server to run composer < 2.0. I also had to do a clean install on my staging server, rather than only updating files whose dates had changed (this is just because I still use SFTP).

I haven’t tested trellis 1.7.0 again yet, but will do shortly.

Following this as I’m having the same issue with the composer.json file. 1.7 Trellis version and have not been able to find any resolution for this.

Even when you use a fresh clone of latest Trellis?