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

时间:2017-03-02 23:48:15

标签: salt-stack

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

2 个答案:

答案 0 :(得分:1)

Salt有模块列出所有用户或获取用户信息

您可以按照 groups post

中的相同方式使用它

对于列出远程系统中用户的模块,请参阅:

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

答案 1 :(得分:0)

您可以查看用户是否' foo'存在以下代码:

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