SaltStack:做...如果组“foo"存在于远程主机上 [英] SaltStack: Do ... if group "foo" exists on remote-host

查看:47
本文介绍了SaltStack:做...如果组“foo"存在于远程主机上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据远程主机是否有一个名为foo"的组来实现条件.

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

我的用例:如果远程主机上有一个名为foo"的组,那么我需要向其中添加一个用户.如果该组不存在,则无需执行任何操作.

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.

SaltStack 可以做到这一点吗?

Is this possible with SaltStack?

推荐答案

您需要 Jinja 渲染器 在您的 salt 状态文件中并与 salt.states.user.present 混合.(更新) .您可以使用盐覆盖模块 pw_group

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 %}

更多覆盖模块 你可以使用.

这篇关于SaltStack:做...如果组“foo"存在于远程主机上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆