Reputation: 2998
I'd like to use saltstack to standardize developers workspaces. As such, I need to take the username as a parameter. This could come from $USER or be typed in. Either would be fine. I see that I could write a grain to expose this, but that seems overly complicated. I'm thinking I'm missing something simpler.
I want to enable something like this
https://...../reponame.git:
git.latest:
- target: '/home/{{ username }}/src/reponame'
- user: {{ username }}
What is the best/easiest way to do this?
Upvotes: 0
Views: 674
Reputation: 243
You can temporarily set/overwrite a pillar at state execution.
So, with a sls (eg. workstation/gitrepo.sls
) like
{% set username = salt['pillar.get']('username') %}
https://...../reponame.git:
git.latest:
- target: '/home/{{ username }}/src/reponame'
- user: {{ username }}
You could call
salt 'phils-pc' state.sls workstation.gitrepo pillar='{"username": "phil"}'
Upvotes: 0
Reputation: 37984
Maybe not elegant, but effective: use the cmd.run
module to get the user that the Salt minion is currently running as (assuming that the Salt minion is running as user, and not as root):
{% set username = salt['cmd.run']('id -u -n') | trim %}
https://...../reponame.git:
git.latest:
- target: '/home/{{ username }}/src/reponame'
- user: {{ username }}
Upvotes: 1