• 03Ansible主机清单


    主机清单

    Inventory:清单,主机清单

    官方链接:https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#

    增加主机组

    [root@ansible-server ~]# vim /etc/ansible/hosts
    [test]
    172.22.69.216
    [web]
    172.22.69.97
    

    这样定义完,进行测试会失败

    [root@ansible-server ~]# ansible web -m ping -o
    

    增加用户名和密码

    [root@ansible-server ~]# vim /etc/ansible/hosts
    [test]
    172.22.69.216 ansible_ssh_user='root' ansible_ssh_pass='123456'
    [web]
    172.22.69.97 ansible_ssh_user='root' ansible_ssh_pass='123456'
    

    这样定义完,就可以免用户名和密码进行测试

    增加端口

    此处假如把172.22.69.216的sshd端口改为2222

    [root@ansible-node ~]# vim /etc/ssh/sshd_config
    Port 2222
    

    ansible服务器连接客户机默认端口是22

    所以需要在 /etc/ansible/hosts 修改端口信息

    [root@ansible-server ~]# vim /etc/ansible/hosts
    [test]
    172.22.69.216 ansible_ssh_user='root' ansible_ssh_pass='123456' ansible_ssh_port='2222'
    [web]
    172.22.69.97 ansible_ssh_user='root' ansible_ssh_pass='123456'
    

    使用变量

    ansible内部变量可以帮助我们简化主机清单的设置

    [root@ansible-server ~]# vim /etc/ansible/hosts
    [test]
    172.22.69.216
    [web]
    172.22.69.97
    [test:vars]
    ansible_ssh_user='root' 
    ansible_ssh_pass='123456' 
    ansible_ssh_port='2222'
    [web]
    ansible_ssh_user='root' 
    ansible_ssh_pass='123456'
    

    常用变量

    使用子分组

    将不同的分组进行组合

    [root@ansible-server ~]# vim /etc/ansible/hosts
    [test]
    172.22.69.216 ansible_ssh_user='root' ansible_ssh_pass='123456' ansible_ssh_port='2222'
    [web]
    172.22.69.97 ansible_ssh_user='root' ansible_ssh_pass='123456'
    [linux:children]
    test
    web
    

    自定义主机列表

    创建主机列表文件

    [root@ansible-server ~]# vim /tmp/hostlist
    [centos]
    172.22.69.217
    172.22.69.218
    [centos:vars]
    ansible_ssh_user='root'
    ansible_ssh_pass='666666'
    

    测试

    [root@ansible-server ~]# ansible -i /tmp/hostlist centos -m ping 
    

    -i 选项指定主机列表文件,以及文件中的主机组

  • 相关阅读:
    Ubuntu12.04 下安装QQ
    python下sqlite增删查改方法(转)
    你有哪些想要分享的 PyCharm 使用技巧?
    PEP 8
    macos 下安装virtualenv,virtualenvwrapper,然后在pycharm中正常配置方法日志
    最全Python爬虫总结(转载)
    Git 常用命令详解
    Python 扩展技术总结(转)
    使用setup.py安装python包和卸载python包的方法
    IPython3 notebook 成功配置Python2和Python3内核(Kernel)
  • 原文地址:https://www.cnblogs.com/ElegantSmile/p/12588799.html
Copyright © 2020-2023  润新知