spin icon indicating copy to clipboard operation
spin copied to clipboard

Incorrect YAML format when provisioning server

Open glennjacobs opened this issue 4 months ago β€’ 17 comments

Current Behavior

I provision a server (using DigitalOcean). When the server is created the spin.yml file is updated with the IP address, but it breaks the YAML format, making it invalid and preventing the rest of the script to run.

Expected Behavior

I expect the YAML file format to be correct when the IP address is added.

Steps To Reproduce

  1. Create a new project using spin new laravel my-billion-dollar-idea
  2. Set DigitalOcean credentials in spin.yml
  3. Run spin provision

Environment

Spin Version: 
v3.0.3 [stable] (User Installed)

Operating System Version: 
ProductName:            macOS
ProductVersion:         15.6
BuildVersion:           24G84

Docker Info: 
WARNING: daemon is not using the default seccomp profile
Client:
 Version:    24.0.6
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.2-desktop.4
    Path:     /Users/glenn/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.21.0-desktop.1
    Path:     /Users/glenn/.docker/cli-plugins/docker-compose
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     /Users/glenn/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.20
    Path:     /Users/glenn/.docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v0.1.0-beta.7
    Path:     /Users/glenn/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/glenn/.docker/cli-plugins/docker-sbom
  scan: Docker Scan (Docker Inc.)
    Version:  v0.26.0
    Path:     /Users/glenn/.docker/cli-plugins/docker-scan
  scout: Command line tool for Docker Scout (Docker Inc.)
    Version:  0.24.1
    Path:     /Users/glenn/.docker/cli-plugins/docker-scout

Server:
 Containers: 25
  Running: 0
  Paused: 0
  Stopped: 25
 Images: 111
 Server Version: 24.0.6
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8165feabfdfe38c65b599c4993d227328c231fca
 runc version: v1.1.8-0-g82f18fe
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.3.13-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 5
 Total Memory: 4.08GiB
 Name: docker-desktop
 ID: 57be98c4-b5f3-4e43-a318-9a0d81a48334
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

glennjacobs avatar Aug 30 '25 20:08 glennjacobs

Thanks so much for posting a detailed bug report!

I almost have the same exact environment as you. I provisioned about 3 Digital Ocean servers last week and did another one for this issue. Unfortunately I was not able to replicate.

The IP came back exactly how it was supposed to be: Image

Can you try running a spin prune to clear any Spin cache and Docker cache and try running again?

Maybe try the whole process over to see if it was a one-time fluke or something? πŸ€”

jaydrogers avatar Sep 02 '25 17:09 jaydrogers

Thanks so much for posting a detailed bug report!

I almost have the same exact environment as you. I provisioned about 3 Digital Ocean servers last week and did another one for this issue. Unfortunately I was not able to replicate.

The IP came back exactly how it was supposed to be: Image

Can you try running a spin prune to clear any Spin cache and Docker cache and try running again?

Maybe try the whole process over to see if it was a one-time fluke or something? πŸ€”

Yep will do.

glennjacobs avatar Sep 02 '25 17:09 glennjacobs

The same happens for me, I don't really know why its happening... But the screenshot shows how the spin.yml is formatted after the IP address is added.

Image
TASK [serversideup.spin.create_server : Store newly created servers in fact] *******************************************************************************
ok: [localhost]

TASK [serversideup.spin.create_server : Refresh inventory] *************************************************************************************************
[WARNING]:  * Failed to parse /etc/ansible/collections/ansible_collections/serversideup/spin/plugins/inventory/spin-dynamic-inventory.sh with script
plugin: failed to parse executable inventory script results from /etc/ansible/collections/ansible_collections/serversideup/spin/plugins/inventory/spin-
dynamic-inventory.sh: Expecting value: line 1 column 1 (char 0). Expecting value: line 1 column 1 (char 0) Error: bad file '/ansible/.spin.yml': yaml: line
38: did not find expected '-' indicator Error: bad file '/ansible/.spin.yml': yaml: line 38: did not find expected '-' indicator Error: bad file
'/ansible/.spin.yml': yaml: line 38: did not find expected '-' indicator Error: bad file '/ansible/.spin.yml': yaml: line 38: did not find expected '-'
indicator Error: bad file '/ansible/.spin.yml': yaml: line 38: did not find expected '-' indicator Error: bad file '/ansible/.spin.yml': yaml: line 38: did
not find expected '-' indicator Error: bad file '/ansible/.spin.yml': yaml: line 38: did not find expected '-' indicator Error: bad file
'/ansible/.spin.yml': yaml: line 38: did not find expected '-' indicator Error: bad file '/ansible/.spin.yml': yaml: line 38: did not find expected '-'
indicator Error: bad file '/ansible/.spin.yml': yaml: line 38: did not find expected '-' indicator
[WARNING]:  * Failed to parse /etc/ansible/collections/ansible_collections/serversideup/spin/plugins/inventory/spin-dynamic-inventory.sh with ini plugin:
/etc/ansible/collections/ansible_collections/serversideup/spin/plugins/inventory/spin-dynamic-inventory.sh:11: Expected key=value host variable assignment,
got: {

LambdaDigamma avatar Sep 04 '25 13:09 LambdaDigamma

Yep, that's exactly what happened for me.

glennjacobs avatar Sep 04 '25 13:09 glennjacobs

Weird! I will definitely take a look into this since there are multiple reports. For some reason I cannot replicate it on my machine, so I will try it on another Mac and see if I can replicate it there.

@LambdaDigamma it looks like you're using Hetzner, so it's not just limited to Digital Ocean?

jaydrogers avatar Sep 05 '25 00:09 jaydrogers

I'm using Hetzner too, and got that 'address' issue where it misses a space. Same logs.

moldygit avatar Sep 05 '25 08:09 moldygit

Any update on this? Having the same issue I think. This is happening when I use the command "spin configure gha production". Screenshot below:

Image

DanjBethel avatar Sep 08 '25 04:09 DanjBethel

I think the reason why I couldn't replicate this is because I had containers cached on my machine πŸ™ƒ

This is a very important issue for me to resolve. I'll get a fix deployed this week for sure πŸ’―

jaydrogers avatar Sep 08 '25 18:09 jaydrogers

@jaydrogers hey don't mean to rush you but any news on this? i'm a new buyer of spinpro and haven't been able to get a deployment up because of this issue.

cheers and thanks for all the hard work.

DanjBethel avatar Sep 11 '25 02:09 DanjBethel

@DanjBethel: I believe it's possible you might be running into a separate issue. It very well could be a syntax issue on your end. Verify your .spin.yml is valid and try running spin provision again. If you still have issues, I would advise opening a new issue and posting more about your set up.

πŸ‘‰ Workaround if time is of the essence

  1. Deploy a server manually through the UI
  2. Ensure you can connect via SSH
  3. Configure your .spin.yml following the Use Any Host method

πŸ› Replicating the original bug (where refreshing the inventory fails because of an automated syntax error)

I am baffled on why I cannot replicate this. Here are my steps and environment that I attempted to reproduce:

Clear local docker cache and spin cache

spin prune

Delete Spin

To be safe, I even deleted Spin:

rm -rf ~/.spin

Re-install Spin

bash -c "$(curl -fsSL https://raw.githubusercontent.com/serversideup/spin/main/tools/install.sh)"

Create a new project

spin new laravel my-billion-dollar-idea

I just use basic settings (doesn't matter).

Configure .spin.yml

Things I made sure to check:

  • [x] Ensure users is set (with my username and SSH key)
  • [x] Ensure providers is set (with my Hetzner API key
  • [x] Ensure servers is set (with my server pointing to a hardware profile)
  • [x] Ensure hardware_profile exists
  • [x] Verify YML spacing is correct and valid
Image

Provision server

spin provision

πŸ‘‰ Actual Results

  • Everything worked as expected πŸ™ƒ
Image

🌎 Environments I tested in

  • Spin Version: 3.0.4
  • macOS: 15.6.1
  • Windows 11 + WSL2

Just to reiterate, I have tested this on my macOS and Windows machine and I am not able to replicate it.

πŸ€” Possible further investigations

  1. The .spin.yml could have improper spacing and/or a syntax error before spin provision is run
  2. Could it be a CRLF issue?

The code where it writes the IP address to the file is here:

https://github.com/serversideup/ansible-collection-spin/blob/806d78782ecdec918006d7a4de5ed2402d444c42/roles/create_server/tasks/create-servers.yml#L28-L33

πŸ‘‡ Next steps

  • Can someone follow my steps above and confirm that you're still having the issue?

jaydrogers avatar Sep 11 '25 19:09 jaydrogers

I think I’ve identified the issue.

When uncommenting any of the blocks in the initial .spin.yml (e.g., in PHPStorm), the editor inserts three leading spaces before the - due to the previous formatting of the comments (two spaces in front and one between the # and -). This is still valid YAML, so there’s no syntax error or warning when parsing the file with a YAML deserializer.

However, your script assumes four leading spaces before the address: xxx.xxx.xxx.xxx attribute. That mismatch leads to the error.

Since the difference between two, three, or four spaces is subtle (especially without β€œVisible Whitespace” enabled – and with three spaces still being valid YAML), it’s very easy to miss.

For example:

servers:
  # - server_name: ubuntu-2gb-ash-1
  #   environment: production
  #   hardware_profile: hetzner_2c_2gb_ubuntu2404

  # - server_name: ubuntu-1gb-ord-2
  #   environment: staging
  #   hardware_profile: vultr_1c_1gb_ubuntu2404

After hitting CMD + Shift + 7, it becomes:

servers:
   - server_name: ubuntu-2gb-ash-1
     environment: production
     hardware_profile: hetzner_2c_2gb_ubuntu2404

  # - server_name: ubuntu-1gb-ord-2
  #   environment: staging
  #   hardware_profile: vultr_1c_1gb_ubuntu2404

One possible fix would be to adjust the formatting before uncommenting so it doesn’t introduce three spaces in front of every line. Another would be to handle the address attribute with a proper YAML formatter instead of hardcoding the indentation.

Hope that clarifies things and helps in finding a good solution!

LambdaDigamma avatar Sep 11 '25 21:09 LambdaDigamma

@jaydrogers hey don't mean to rush you but any news on this? i'm a new buyer of spinpro and haven't been able to get a deployment up because of this issue.

cheers and thanks for all the hard work.

@jaydrogers yikes completely my fault with this one. didn't realize that i needed to run spin provision before the gh configure command. sorry about that!

DanjBethel avatar Sep 11 '25 23:09 DanjBethel

You rock @LambdaDigamma!!

Just wanted to put I note that I was able to replicate this if I use PHPStorm (wow, first time for that πŸ™ƒ):

Image

Let me see if I can play around with solutions. I think @LambdaDigamma had some great proposals.

I'll keep you guys posted πŸ‘

jaydrogers avatar Sep 12 '25 15:09 jaydrogers

Update

I pushed up this commit, which should fix this -- but it's not a 100% solution https://github.com/serversideup/ansible-collection-spin/commit/34b3e5c86199bbf7a9fbbbc375087ba2a7ba0792

The "True solution"

The above fix only fixes the specific issue for un-commenting in PHPStorm. It does not solve that if someone uses different delimiters or number of spaces in their file.

Solving different delimiters

I've been working on this all day, but ran into a "ready for the weekend brain rot" scenario. Here's where I left off:

  • [ ] Look into using something like yedit to directly modify the data structure instead of a file
  • [ ] If I get that to work, I should include a section for yamllint that will validate the syntax of a .spin.yml file before Ansible even runs (this will execute yamllint from within the container, so nobody will even need to install anything)

Next steps (for people on this thread)

  • Test it out and let me know if this works on new projects. At least what I committed so far should fix your issue for now
  • I will keep you posted once I think on this a bit more πŸ‘

jaydrogers avatar Sep 12 '25 20:09 jaydrogers

Just nudging this thread to see if my fix worked for everyone πŸ˜…

jaydrogers avatar Sep 19 '25 11:09 jaydrogers

Just adding a note that the current implementation needs to be reworked regardless.

πŸ› Additional bug

If someone attempts to provision a server with an encrypted .spin.yml file, our "lineinfile" just adds it to the bottom without actually decrypting it and inserting it

Image

jaydrogers avatar Sep 23 '25 17:09 jaydrogers

Just nudging this thread to see if my fix worked for everyone πŸ˜…

Came across this issue yesterday and what finally worked for me was clearing the docker cache and reinstalling spin like suggested.πŸŽ‰

Clear local docker cache and spin cache

spin prune

Delete Spin

To be safe, I even deleted Spin:

rm -rf ~/.spin

Re-install Spin

bash -c "$(curl -fsSL https://raw.githubusercontent.com/serversideup/spin/main/tools/install.sh)"

albertricart avatar Sep 24 '25 11:09 albertricart