Creating files from contents of another file
Description of Issue
I want to create a file in /etc/sudoers.d for each developer. I was thinking about having a file in the files directory with each of their login ids in it. Then from that, for each developer, create a file in /etc/sudoers.d giving that user his/her sudo privileges. I'm just not sure of the correct approach. If someone could point me in the correct direction, I would appreciate it.
Setup
RHEL 7, salt 2018.3.4.
Got it worked out. In my file/sudoers.template I put in: {{ SID}} ALL = (ALL) ALL. In my state file, I added: {% for sid in ['user1', 'user2', 'user3' ] %}
/etc/sudoers.d/{{ sid }}
file.managed:
- source: salt://compliance/files/sudoers.template
- user: root
- group: root
- mode: '0440'
- template: jinja
- defaults:
SID: {{ sid }}
{% endfor %} and that seemed to work correctly. :)
I'd like to get the list of users out of the salt state so that I don't have to change the salt state every time a users comes or goes. I'd rather have the salt state read from a file. I was trying: {% for sids in salt['cmd.shell']('cat /root/sids') %}, but salt doesn't like that. Does anyone have a better suggestion on how to read the list of sids from a file?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
Thank you for updating this issue. It is no longer marked as stale.
My jinja for loop has been working fine. Can close this. Thanks!