Deployment ansible为每个流浪vm设置/etc/hosts 我的流浪汉档案 用于生成/etc/host的ansible tamplate 负责任任务 但我得到了结果 命令
我在ifconfig中发现,host01和host02上只有enp0s8 inet 192.168.11.102不同 host01和host02的ip相同 host01有一个docker注册表 01号酒店http://host01:5006/v2/_catalog 作品 02号旅社,curlhttp://host01:5006/v2/_catalog 不行 host01和host02的ip相同 对。这就是Vagrant的工作原理,它能够连接到来自不同出版商的各种盒子中创建的机器,以便进行编排 这并不奇怪,它们连接到VirtualBox中的不同虚拟交换机 我只希望host01和host02可以通过主机名相互访问Deployment ansible为每个流浪vm设置/etc/hosts 我的流浪汉档案 用于生成/etc/host的ansible tamplate 负责任任务 但我得到了结果 命令,deployment,vagrant,ansible,vagrantfile,ansible-2.x,Deployment,Vagrant,Ansible,Vagrantfile,Ansible 2.x,我在ifconfig中发现,host01和host02上只有enp0s8 inet 192.168.11.102不同 host01和host02的ip相同 host01有一个docker注册表 01号酒店http://host01:5006/v2/_catalog 作品 02号旅社,curlhttp://host01:5006/v2/_catalog 不行 host01和host02的ip相同 对。这就是Vagrant的工作原理,它能够连接到来自不同出版商的各种盒子中创建的机器,以便进行编排
在Jinja2模板中使用另一个接口作为iface的值,但问题中没有显示它。我更新了有问题的ifconfig,你的意思是吗?我不熟悉ansible模板变量,该代码是从gist复制的。iface的第二个接口的价值是什么?它是ifconfig enp0s8吗?您的模板中有“ansible”+iface。为iface分配适当的值。我不知道是什么。你正坐在电脑前。使用调试和复制粘贴接口名称显示事实。我也不知道去哪里。使用grep查找您设置值的位置。您是对的,grep-RH ansible\u default\u ipv4查找如果在组\u vars/all中设置了ce,则其值为ansible\u default\u ipv4.interface。谷歌这只是提出了很多问题。是否有任何关于如何使用此变量的文档,例如ansible_default_ipv4.interface[1]引用第二个接口?针对正确的目标执行它。对不起,我不会指导您在键盘上按什么键,这是您当前的要求。请自己处理。我只回答了你问的问题。
hosts = {
"host01" => "192.168.11.101",
"host02" => "192.168.11.102",
}
Vagrant.configure("2") do |config|
config.ssh.username = "root"
config.ssh.password = "vagrant"
config.ssh.insert_key = "true"
hosts.each_with_index do |(name,ip),index|
config.vm.define name do |machine|
machine.vm.box = "centos7"
machine.vm.box_check_update = false
machine.vm.hostname = name
machine.vm.synced_folder "/data", "/data"
machine.vm.network :private_network, ip: ip
machine.vm.provider "virtualbox" do |v|
v.name = name
v.customize ["modifyvm", :id, "--memory", 2048]
end
end
end
end
127.0.0.1 localhost
{% for host in groups['all'] %}
{{ hostvars[host]['ansible_' + iface].ipv4.address }} {{ host }}
{% endfor %}
- name: Create the hosts file for all machines
template: src=hosts.j2 dest=/etc/hosts
[root@host01 ~]# cat /etc/hosts
127.0.0.1 localhost
10.0.2.15 host01
10.0.2.15 host02
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
inet6 fe80::42:49ff:fed1:eebb prefixlen 64 scopeid 0x20<link>
ether 02:42:49:d1:ee:bb txqueuelen 0 (Ethernet)
RX packets 77 bytes 6065 (5.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 99 bytes 8572 (8.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:fede:e0e prefixlen 64 scopeid 0x20<link>
ether 08:00:27:de:0e:0e txqueuelen 1000 (Ethernet)
RX packets 785483 bytes 57738892 (55.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 777457 bytes 1957320412 (1.8 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.11.101 netmask 255.255.255.0 broadcast 192.168.11.255
ether 08:00:27:15:2c:64 txqueuelen 1000 (Ethernet)
RX packets 41445 bytes 39878552 (38.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18055 bytes 2113498 (2.0 MiB)