Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SaltStack: Do ... if group "foo" exists on remote-host

Tags:

salt-project

How can I implement a condition bases on the fact that the remote-host a group called "foo" or not.

My use case: If there is a group called "foo" on the remote-host, then I need to add a user to it. If the group does not exist, then nothing needs to be done.

Is this possible with SaltStack?

like image 931
guettli Avatar asked Mar 16 '26 20:03

guettli


1 Answers

You need Jinja renderers in your salt states file and mix with salt.states.user.present. (Update) . you can use an salt override modules pw_group

{% if salt['group.info']("foo") %}
add new user if foo group found:
    user.present:
        - name: foouser
{% endif %}

There is more override modules that you may use.

like image 160
mootmoot Avatar answered Mar 18 '26 10:03

mootmoot