YJWANG

[Ansible] Hostname 변경 본문

91.IaC

[Ansible] Hostname 변경

왕영주 2021. 1. 26. 17:50

inventory 파일 sample

[root@addon01_deploy_0 kubespray]# cat inventory/addon/inventory.ini

[all]
addon-master1 ansible_host=10.18.90.10 etcd_member_name=etcd1
addon-worker1 ansible_host=10.18.90.20 etcd_member_name=etcd2
addon-worker2 ansible_host=10.18.90.21 etcd_member_name=etcd3

ansible adhoc 실행

[root@addon01_deploy_0 kubespray]# ansible -m hostname -a 'name="{{ inventory_hostname }}"' -i inventory/addon/inventory.ini all
addon-worker2 | CHANGED => {
    "ansible_facts": {
        "ansible_domain": "",
        "ansible_fqdn": "addon-worker2",
        "ansible_hostname": "addon-worker2",
        "ansible_nodename": "addon-worker2"
    },
    "changed": true,
    "name": "addon-worker2"
}
addon-master1 | CHANGED => {
    "ansible_facts": {
        "ansible_domain": "",
        "ansible_fqdn": "addon-master1",
        "ansible_hostname": "addon-master1",
        "ansible_nodename": "addon-master1"
    },
    "changed": true,
    "name": "addon-master1"
}
addon-worker1 | CHANGED => {
    "ansible_facts": {
        "ansible_domain": "",
        "ansible_fqdn": "addon-worker1",
        "ansible_hostname": "addon-worker1",
        "ansible_nodename": "addon-worker1"
    },
    "changed": true,
    "name": "addon-worker1"
}

확인

[root@addon01_deploy_0 kubespray]# ansible -m shell -a 'hostname' -f 1 -i inventory/addon/inventory.ini all
addon-master1 | CHANGED | rc=0 >>
addon-master1
addon-worker1 | CHANGED | rc=0 >>
addon-worker1
addon-worker2 | CHANGED | rc=0 >>
addon-worker2
반응형