saltstack动态更新等主机

时间:2014-07-03 12:53:44

标签: salt-stack configuration-management

如何使用saltstack动态更新/ etc / hosts文件。

有一个例子与ansible有效,但不知道如何用盐做。

http://xmeblog.blogspot.fr/2013/06/ansible-dynamicaly-update-etchosts.html

  - name: add hostname in /etc/hosts
    lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{item}}" state=present
    when: hostvars[item]['ansible_default_ipv4']['address'] is defined
    with_items: groups['all']

这将使用库存文件中提供的所有ansible hosts-ip和主机地址更新/ etc / hosts。

用盐怎么可能? 我想收集所有minions的ip地址和主机名,并在所有minions / etc / hosts上更新它。

minion1 => ip (192.168.1.1) hostname is (example1.net)
minion2 => ip (192.168.1.2) hostname is (example2.net)
minion3 => ip (192.168.1.3) hostname is (example3.net)

在所有minions / etc / hosts中,文件条目应该是:

127.0.0.1 localhost
::1 localhost
192.168.1.1  example1.net
192.168.1.2  example2.net
192.168.1.3  example3.net

1 个答案:

答案 0 :(得分:2)

请查看https://github.com/saltstack-formulas/hostsfile-formula,希望它符合您的需求。

此特定公式允许为所有已知的小兵“自动”创建/etc/hosts条记录。

请不要,我注意到公式文档的公式链接已被破坏,请尝试使用此Salt Formulas installation and usage instructions.


Salt Formulas explained

  

公式是预先写好的Salt States。它们与Salt States本身一样开放,可用于安装软件包,配置和启动服务,设置用户或权限以及许多其他常见任务等任务。

相关问题