SaltStack: Do … if group “foo” exists on remote-host

百般思念 提交于 2019-12-10 21:14:45

问题


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?


回答1:


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.




回答2:


If you want to create the user on the system and add the user to certain groups only if the groups exist, the user.present state has an optional_groups option that will do that.

https://docs.saltstack.com/en/latest/ref/states/all/salt.states.user.html#salt.states.user.present



来源:https://stackoverflow.com/questions/37298827/saltstack-do-if-group-foo-exists-on-remote-host

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!