I just started over with a fresh site trellis new
in a new directory and now I’m not getting the error. (I did make some changes, so I just wanted to see if I can get this working fresh, then I can slowly re-introduce my changes)
My end goal is to hopefully use bitbucket CI/CD to deploy this. I setup ssh keys correctly to my server (on digital ocean) and here is my bitbucket-pipelines.yml file:
image: nikolaik/python-nodejs
options:
max-time: 10
pipelines:
branches:
test:
- step:
name: Deploy to server
caches:
- pip
script:
- cd trellis
- pip install -r requirements.txt
- ansible-galaxy install -r galaxy.yml
- ansible-playbook deploy.yml -vvv -e "site=testing.example.com env=staging" -i hosts/staging
And that’s the error I get:
TASK [deploy : Copy project templates] *****************************************
task path: /opt/atlassian/pipelines/agent/build/trellis/roles/deploy/tasks/build.yml:17
<XXX.XXX.XXX.XXX> ESTABLISH SSH CONNECTION FOR USER: web
<XXX.XXX.XXX.XXX> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="web"' -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/cb9dacd761"' XXX.XXX.XXX.XXX '/bin/sh -c '"'"'echo ~web && sleep 0'"'"''
<XXX.XXX.XXX.XXX> (0, b'/home/web\n', b'')
<XXX.XXX.XXX.XXX> ESTABLISH SSH CONNECTION FOR USER: web
<XXX.XXX.XXX.XXX> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="web"' -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/cb9dacd761"' XXX.XXX.XXX.XXX '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /home/web/.ansible/tmp `"&& mkdir "` echo /home/web/.ansible/tmp/ansible-tmp-1679335124.353757-287-194313047771109 `" && echo ansible-tmp-1679335124.353757-287-194313047771109="` echo /home/web/.ansible/tmp/ansible-tmp-1679335124.353757-287-194313047771109 `" ) && sleep 0'"'"''
<XXX.XXX.XXX.XXX> (0, b'ansible-tmp-1679335124.353757-287-194313047771109=/home/web/.ansible/tmp/ansible-tmp-1679335124.353757-287-194313047771109\n', b'')
<XXX.XXX.XXX.XXX> ESTABLISH SSH CONNECTION FOR USER: web
<XXX.XXX.XXX.XXX> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="web"' -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/cb9dacd761"' 142.93.204.216 '/bin/sh -c '"'"'rm -f -r /home/web/.ansible/tmp/ansible-tmp-1679335124.353757-287-194313047771109/ > /dev/null 2>&1 && sleep 0'"'"''
<XXX.XXX.XXX.XXX> (0, b'', b'')
The full traceback is:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/ansible/template/__init__.py", line 445, in __getitem__
func = self._delegatee[key]
~~~~~~~~~~~~~~~^^^^^
KeyError: 'to_env'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/ansible/template/__init__.py", line 952, in do_template
t = myenv.from_string(data)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 1105, in from_string
return cls.from_code(self, self.compile(source), gs, None)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 768, in compile
self.handle_exception(source=source_hint)
File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<unknown>", line 1, in template
jinja2.exceptions.TemplateSyntaxError: Could not load "to_env": 'to_env'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/ansible/plugins/action/template.py", line 141, in run
resultant = templar.do_template(template_data, preserve_trailing_newlines=True, escape_backslashes=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/ansible/template/__init__.py", line 954, in do_template
raise AnsibleError("template error while templating string: %s. String: %s" % (to_native(e), to_native(data)), orig_exc=e)
ansible.errors.AnsibleError: template error while templating string: Could not load "to_env": 'to_env'. String: {{ site_env | to_env }}
. Could not load "to_env": 'to_env'
failed: [XXX.XXX.XXX.XXX] (item=.env config) => {
"ansible_loop_var": "item",
"changed": false,
"item": {
"dest": ".env",
"mode": "0600",
"name": ".env config",
"src": "roles/deploy/templates/env.j2"
},
"msg": "AnsibleError: template error while templating string: Could not load \"to_env\": 'to_env'. String: {{ site_env | to_env }}\n. Could not load \"to_env\": 'to_env'"
}
PLAY RECAP *********************************************************************
XXX.XXX.XXX.XXX : ok=11 changed=3 unreachable=0 failed=1 skipped=24 rescued=0 ignored=0
localhost : ok=0 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
But running trellis deploy staging
or running ansible-playbook deploy.yml -vvv -e "site=testing.example.com env=staging" -i hosts/staging
both work fine.
So I guess my question is really more about how to get CI/CD working here…