일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- cephadm
- kolla
- archlinux
- golang
- HTML
- Docker
- nfs-provisioner
- i3
- kolla-ansible
- ceph
- libvirt
- port open
- Kubernetes
- grafana-loki
- ceph-ansible
- awx
- yum
- ubuntu
- k8s
- repository
- Linux
- Kubeflow
- KVM
- cloud-init
- terraform
- Arch
- Ansible
- pacman
- OpenStack
- Octavia
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
반응형