【问题标题】:saltstack dynamically update etc hostssaltstack 动态更新等主机
【发布时间】:2015-12-08 20:18:26
【问题描述】:

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

有一个例子可以很好地使用ansible,但不知道如何使用salt。

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']

这将使用清单文件中所有可用的主机 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

【问题讨论】:

    标签: salt-stack configuration-management


    【解决方案1】:

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

    这个特殊的公式允许为所有已知的奴才“自动”创建/etc/hosts 记录。

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


    Salt Formulas explained

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多