Search code examples
salt-project

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


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?


Solution

  • 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.