Allow jinja templates while provisioning #23
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I used this to dynamically set the hostname based on templates. instead of having to create a file for every vm etc.
This should work for all provisioning cases I found.
you should be able to set additional template args as well .. name is implied.
"provision": [
{
"type": "shell",
"inline": "echo {{name}} > /tmp/out2",
"template": "True"
},
{
"type": "shell",
"path": "./salt-minion.sh",
"template": "True"
},
{
"type": "file",
"source": "./temporary.txt",
"destination": "/tmp/temporary.txt",
"template": "True"
}
]
more temporary.txt
{{name}}
more salt-minion.sh
#!/bin/bash
sudo mkdir -p /etc/salt
Set the minion id
sudo sh -c "echo {{name}} > /etc/salt/minion_id"
sudo wget -O - https://repo.saltstack.com/py3/ubuntu/20.04/amd64/latest/SALTSTACK-GPG-KEY.pub | sudo apt-key add -
sudo sh -c "echo 'deb http://repo.saltstack.com/py3/ubuntu/20.04/amd64/latest focal main' > /etc/apt/sources.list.d/saltstack.list"
sudo apt-get update
sudo apt-get -y install salt-minion
Set the hostname
sudo salt-call --local network.mod_hostname {{name}}
Restart the salt-minion service
sudo service salt-minion restart