Ezequiel Biavaschi
Ezequiel Biavaschi

Reputation: 23

How to check if a remote user exists on a SaltStack state

I'm writing a SaltStack state, and I need to know if a remote user exists to do or don't do something.

I need something like this:

{% if user foo exists %}
  do something
{% endif %}

I've tried with user.present, user.absent, but nothing of this does what I need.

Someone have done this, but with remote groups: SaltStack: Do ... if group "foo" exists on remote-host

Is this possible? Thanks

Upvotes: 1

Views: 3712

Answers (2)

Davide Madrisan
Davide Madrisan

Reputation: 2300

You can check if the user 'foo' exists with the following code:

{% set all_users = salt['user.list_users']() %}
{% if 'foo' in all_users %}
  do something
{% endif %}

Upvotes: 2

chaitu kopparthi
chaitu kopparthi

Reputation: 170

Salt have module to list All users or to get User info

you can use it in the same way as they did in the groups post

for the module that lists user's in remote system please refer:

https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.useradd.html#salt.modules.useradd.list_users

Upvotes: 1

Related Questions