美文网首页
Ansible配置主机名

Ansible配置主机名

作者: MOUSELET_fb2b | 来源:发表于2021-06-22 09:01 被阅读0次

本文章分享ansible配置Linux主机名,以及/etc/hosts文件的方法

  1. 编辑文件inventory
node1 ansible_ssh_host=192.168.56.101 ansible_ssh_port=22 ansible_ssh_pass=*****
node2 ansible_ssh_host=192.168.56.102 ansible_ssh_port=22 ansible_ssh_pass=*****

[cluster]
node[1:2]

#部署节点,执行playbook的节点
[deploy]
node1

2.编辑文件set_hostname.yml

---
# set_hostname.yml
- hosts: cluster
  tasks:
    - name: Set Hostname
      hostname:
        name: "{{ inventory_hostname }}"

    - name: Config HOSTS FILE
      blockinfile:
        marker_begin: BEGIN
        marker_end: END
        path: /etc/hosts
        block: "{% for item in groups.cluster %}
        {{ hostvars[item]['ansible_ssh_host'] }}  {{item}}

        {% endfor %}"

3.执行剧本


截屏2021-06-22 上午9.00.58.png

相关文章

网友评论

      本文标题:Ansible配置主机名

      本文链接:https://www.haomeiwen.com/subject/gcspyltx.html