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