これなに
- 以下の様に
/etc/hosts
があったとする。- 往々にして雑なコメントアウトがあったりする。
/etc/hosts
192.168.1.1 R1
192.168.1.2 R2
192.168.1.3 R3
# 192.168.1.4 R4 (現在設置中)
- これを以下のように変換したい
inventory_for_ansible
R1 ansible_host=192.168.1.1
R2 ansible_host=192.168.1.2
R3 ansible_host=192.168.1.3
ワンライナー
- あっさり。
~/
cat /etc/hosts | grep -v "#" | awk '{printf "%s \t ansible_host=%s\n",$2,$1}' > inventory