ansible预计实现功能,自动生成/etc/hosts文件,copy到远程机器,出现如下错误:
配置如下:
---
- hosts: 192.168.31.12
remote_user: cluster
sudo: yes
tasks:
- name: dirstribute host file
template: src=templates/hosts.j2 dest=/tmp/hosts
hosts.j2
127.0.0.1 localhost
{{ ansible_eth0.ipv4.address }} {{ ansible_hostname }}
{% for host in groups['all'] %}
{{ hostvars[host].ansible_eth0.ipv4.address }} {{ hostvars[host].ansible_hostname }}
{% endfor %}
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
cat /etc/ansible/hosts
[all]
192.168.31.10
192.168.31.12
ifconfig
eno16777984: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.31.12 netmask 255.255.255.0 broadcast 192.168.31.255
inet6 fe80::20c:29ff:fe5c:520e prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:5c:52:0e txqueuelen 1000 (Ethernet)
RX packets 3645802 bytes 780617081 (744.4 MiB)
RX errors 32 dropped 8430 overruns 0 frame 0
TX packets 985366 bytes 509863584 (486.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 18000 bytes 988080 (964.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18000 bytes 988080 (964.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
解决后:
ansible 192.168.31.12 -m setup -a 'filter=ansible_eno16777984'
192.168.31.12 | success >> {
"ansible_facts": {
"ansible_eno16777984": {
"active": true,
"device": "eno16777984",
"ipv4": {
"address": "192.168.31.12",
"netmask": "255.255.255.0",
"network": "192.168.31.0"
},
"ipv6": [
{
"address": "fe80::20c:29ff:fe5c:520e",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "00:0c:29:5c:52:0e",
"module": "vmxnet3",
"mtu": 1500,
"promisc": false,
"type": "ether"
}
},
"changed": false
}
固更改hosts.j2文件:
cat hosts.j2
127.0.0.1 localhost
{{ ansible_eno16777984.ipv4.address }} {{ ansible_hostname }}
{% for host in groups['all'] %}
{{ hostvars[host].ansible_eno16777984.ipv4.address }} {{ hostvars[host].ansible_hostname }}
{% endfor %}
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
标签:Ansible,192.168,hosts,host,ansible,ip6,报错,eno16777984
From: https://blog.csdn.net/qq_43606536/article/details/141824123