일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Ansible
- Docker
- Kubeflow
- Octavia
- kolla-ansible
- cephadm
- k8s
- archlinux
- port open
- Linux
- Kubernetes
- ceph
- yum
- grafana-loki
- kolla
- repository
- OpenStack
- pacman
- KVM
- terraform
- golang
- awx
- ubuntu
- ceph-ansible
- nfs-provisioner
- cloud-init
- libvirt
- Arch
- i3
- HTML
Archives
- Today
- Total
YJWANG
Ansible /etc/hosts 자동화 본문
파일 준비
[root@yjwang1102-deploy-1 pre-ansible]# cat inventory
[ceph]
ceph01 ansible_host=10.10.90.30
ceph02 ansible_host=10.10.90.31
ceph03 ansible_host=10.10.90.32
[root@yjwang1102-deploy-1 pre-ansible]# cat hosts.yml
---
- name: gen etc hosts
hosts: all
tasks:
- name: lineinfile
lineinfile:
path: /etc/hosts
line: "{{ hostvars[item]['ansible_facts']['default_ipv4']['address'] }} {{ hostvars[item]['ansible_facts']['hostname'] }}"
loop: "{{ ansible_play_hosts }}"
...
or
---
- name: gen etc hosts
hosts: all
tasks:
- name: lineinfile
lineinfile:
path: /etc/hosts
line: "{{ hostvars[item]['ansible_host'] }} {{ hostvars[item]['inventory_hostname'] }}"
loop: "{{ ansible_play_hosts }}"
수행
[root@yjwang1102-deploy-1 pre-ansible]# ansible-playbook -i inventory hosts.yml
반응형