I’ve never used write_files, but we use this method to communicate tags to the machine:
{{py:
ansible_key = "REDACTED"
git_identity = "REDACTED"
git_url = "REDACTED"
}}
...
late_commands:
...
13_provision: ["curtin", "in-target", "--", "sh", "-c", "echo {{git_identity}} >> /root/.ssh/known_hosts"]
14_provision: ["curtin", "in-target", "--", "sh", "-c", "echo -----BEGIN OPENSSH PRIVATE KEY----- > /root/.ssh/machine-deploy-key"]
15_provision: ["curtin", "in-target", "--", "sh", "-c", "echo {{ansible_key}} >> /root/.ssh/machine-deploy-key"]
16_provision: ["curtin", "in-target", "--", "sh", "-c", "echo -----END OPENSSH PRIVATE KEY----- >> /root/.ssh/machine-deploy-key"]
20_provision: ["curtin", "in-target", "--", "sh", "-c", "GIT_SSH_COMMAND='ssh -i /root/.ssh/machine-deploy-key -o IdentitiesOnly=yes' git clone {{git_url}} --depth 1 /tmp/maas-deploy-bootstrap"]
30_provision: ["curtin", "in-target", "--", "sh", "-c", "/bin/bash /tmp/maas-deploy-bootstrap/00-configure-node.sh -z {{node.zone.name}} -t '{{node.tag_names()}}'"]
That bash script then has access to the tags (and zone) from its args. The above created files persist after first boot, so you might be able to use this to inform your efforts.