mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 14:30:52 +00:00
fix(deploy): pass list extra vars as compact JSON
ansible-playbook splits each -e value through parse_kv on whitespace, so json.dumps' default ', ' separator broke PRIMARY_APPS=["a", "b"] into a raw parameter and the list never reached the play. Dump extra vars with separators=(',', ':') in the development deploy and the swarm matrix deploy, and test that a list extra var survives parse_kv.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
03217e415d
commit
c8625c4592
3 files changed
+18
-3
No files matched your search
@@ -1,14 +1,17 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest import mock
|
||||
|
||||
from ansible.parsing.splitter import parse_kv
|
||||
|
||||
from cli.administration.deploy.development.deploy.run import _run_deploy
|
||||
|
||||
|
||||
class TestRunDeploy(unittest.TestCase):
|
||||
def deploy_cmd(self) -> list[str]:
|
||||
def deploy_cmd(self, extra_ansible_vars=None) -> list[str]:
|
||||
compose = mock.Mock()
|
||||
compose.exec.return_value = SimpleNamespace(returncode=0)
|
||||
_run_deploy(
|
||||
@@ -18,9 +21,21 @@ class TestRunDeploy(unittest.TestCase):
|
||||
passthrough=[],
|
||||
inventory_dir="/etc/inventories/dev",
|
||||
container_name="infinito",
|
||||
extra_ansible_vars=extra_ansible_vars,
|
||||
)
|
||||
return compose.exec.call_args.args[0]
|
||||
|
||||
def test_a_list_extra_var_survives_ansible_key_value_parsing(self):
|
||||
apps = ["web-app-gitea", "web-app-lam"]
|
||||
cmd = self.deploy_cmd({"PRIMARY_APPS": apps, "VARIANT_INDEX": 0})
|
||||
extra_vars = [cmd[i + 1] for i, arg in enumerate(cmd) if arg == "-e"]
|
||||
parsed = {}
|
||||
for extra_var in extra_vars:
|
||||
parsed.update(parse_kv(extra_var))
|
||||
self.assertNotIn("_raw_params", parsed)
|
||||
self.assertEqual(apps, json.loads(parsed["PRIMARY_APPS"]))
|
||||
self.assertEqual(0, json.loads(parsed["VARIANT_INDEX"]))
|
||||
|
||||
def test_deploys_the_generated_inventory(self):
|
||||
cmd = self.deploy_cmd()
|
||||
self.assertEqual("/etc/inventories/dev/devices.yml", cmd[3])
|
||||
|
||||
Reference in new issue
Block a user