salt icon indicating copy to clipboard operation
salt copied to clipboard

Creating files from contents of another file

Open bradawk1 opened this issue 7 years ago • 5 comments

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.

bradawk1 avatar Sep 19 '19 13:09 bradawk1

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. :)

bradawk1 avatar Sep 20 '19 15:09 bradawk1

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?

bradawk1 avatar Oct 01 '19 15:10 bradawk1

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.

stale[bot] avatar Jan 07 '20 11:01 stale[bot]

Thank you for updating this issue. It is no longer marked as stale.

stale[bot] avatar Jan 09 '20 19:01 stale[bot]

My jinja for loop has been working fine. Can close this. Thanks!

bradawk1 avatar Apr 19 '21 14:04 bradawk1