rename windows minion from master

122 views
Skip to first unread message

Jeremy Larose

unread,
Aug 16, 2016, 4:37:40 PM8/16/16
to Salt-users
Is there a way to do this? I'd like to clean up my key list and possibly group computers by names.  This is close (works directly on the machine), but salt can't cmd.run it...

powershell "(Get-Content C:\salt\conf\minion) -replace 'id:.*', ('id: newname') | Set-Content C:\salt\conf\minion" && echo newname > C:\salt\conf\minion_id

and then the service would just need to be restarted.

Thanks.

Loren Gordon

unread,
Aug 16, 2016, 9:19:42 PM8/16/16
to Salt-users
Have you tried just using `file.replace`? Also, from a bit of research, looks like you can just delete the minion_id file and let it regenerate.

-Loren

Jeremy Larose

unread,
Aug 16, 2016, 10:54:49 PM8/16/16
to Salt-users
using your suggestion of file.replace, maybe not the cleanest, but this works:

salt 'oldname' file.uncomment 'c:\salt\conf\minion' 'id:'
salt 'oldname' file.replace 'c:\salt\conf\minion' pattern='id: oldname' repl='id: newname'
salt 'oldname' service.restart salt-minion
salt-key -d 'oldname'
salt-key -a 'newname'

Loren Gordon

unread,
Aug 17, 2016, 5:54:38 AM8/17/16
to Salt-users
Looks pretty clean to me. file.replace accepts regex patterns, which you could probably use to uncomment the line.

salt 'oldname' file.replace 'c:\salt\conf\minion' pattern='^[#]?id:.*$' repl='id: newname'

Untested, but, something along those lines...

You can also write a file to 'C:\salt\conf\minion.d\<myconfig.conf>' to store your config settings.

And if you changed the windows computer name, I'm pretty sure you can just remove/rename the minion_id file and restart the minion service. At least, on my own computer, I'm not seeing any other reference to the minion id anywhere, and this does regenerate the minion_id file.

-Loren

Jeremy Larose

unread,
Aug 22, 2016, 10:46:35 AM8/22/16
to Salt-users
It seems as though the main minion config file overrides the minion_id file... but this is the final, one liner that I have been using with success...

salt 'oldname' file.uncomment 'c:\salt\conf\minion' 'id:' && salt 'oldname' file.replace 'c:\salt\conf\minion' pattern='^[#]?id:.*$' repl='id: newname' && salt 'oldname' service.restart salt-minion && salt-key -d 'oldname' -y && sleep 5 && salt-key -a 'newname' -y

Sindhu Reddy

unread,
Jul 25, 2018, 10:45:29 AM7/25/18
to Salt-users
It worked!! Thanks :) That's awesome
Reply all
Reply to author
Forward
0 new messages