如何配置salt-ssh的名单?

时间:2017-04-22 22:19:08

标签: salt-stack

如何使用通用参数'user'为所有节点配置salt-ssh的名册文件[/ etc / salt / roster]?

我已经在下面的文档中搜索了它但找不到它。   https://docs.saltstack.com/en/latest/topics/ssh/index.html#salt-ssh-roster   https://docs.saltstack.com/en/latest/topics/ssh/roster.html

这就是我现在所拥有的:

host1-dev:
    host: host1-dev.mydomain.com
    user: myUser
host2-dev:
    host: host2-dev.mydomain.com
    user: myUser
host1-qa:
    host: host1-qa.mydomain.com
    user: myUser

希望简化下面的内容:

common:
    user: myUser
host1-dev:
    host: host1-dev.mydomain.com
host2-dev:
    host: host2-dev.mydomain.com
host1-qa:
    host: host1-qa.mydomain.com

1 个答案:

答案 0 :(得分:1)

Jinja拯救了,虽然你无法达到你想要的,但是你可以用这样的东西来节省一些打字:

{% set hosts = ['host1-dev.mydomain.com', 'host2-dev.mydomain.com', 'host1-qa.mydomain.com'] %}
{% set user = 'some_user' %}
{% set pass = 'some_pass' %}

{% for host in hosts %}
{{ host.split('.')[0] }}:
  host: {{ host }}
  user: {{ user }}
  passwd: {{ pass }}
{% endfor %}