Ansible:从列表中

时间:2017-11-01 18:14:41

标签: ansible

我有一个应根据特定主机名为主机分配的IPv6地址列表。例如:

  • 主机名为" myhost-dev1" 应该有fd00:1 :: 1/64
  • 主机名为" myhost-dev2" 应该有fd00:1 :: 2/64
  • ...
  • 主机名为" myhost-devN" 应该有fd00:1 :: N / 64
  • ...
  • 主机名为" myhost-qa1" 应该有fd00:2 :: 1/64
  • 主机名为" myhost-qaM" 应该有fd00:2 :: M / 64
  • ...
IPv4 addresses are already assigned.
Question: what is the best way to assign these addresses using Ansible?

1 个答案:

答案 0 :(得分:0)

以下是解决问题的方法:

  1. 创建v6.yaml文件:

    myhost-dev1.example.com: fd00:1::1
    myhost-dev2.example.com: fd00:1::2
    
  2. 添加了以下两项任务:

    - name: Load IPv6 addresses list
      include_vars:
        file: 'v6.yml'
        name: ipv6_addr
    
    - name: Apply IPv6 addresses
      blockinfile:
        path: '/etc/sysconfig/network-scripts/ifcfg-eth0'
        block: |
          IPV6INIT=yes
          IPV6ADDR={{ ipv6_addr[ansible_fqdn] }}
          IPV6_DEFAULTGW=fd00:1::100