zoukankan      html  css  js  c++  java
  • 02Ansible入门

    Ansible入门

    定义主机清单

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

    在主机清单中未定义的主机,无法使用ansible进行管理。

    测试连通性

    [root@ansible-server ~]# ansible test -m ping
    172.22.69.216 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "ping": "pong"
    }
    

    test 是 /etc/ansible/hosts 中定义的主机

    -m 指定模块

    ping 是指定的模块,用于测试客户端是否能够连接,除此之外还有很多模块,比如shell,yum等

    如果在/etc/ansible/hosts中没有指定主机的用户名和密码,就需要:

    [root@ansible-server ~]# ansible test -m ping -u root -k -o 
    # 手动输入密码
    

    取消安全主机提示:

    [root@ansible-server ~]# vim /etc/ssh/ssh_config
    StrictHostKeyChecking no
    

    不然每个客户机的第一次连接会提示

    简洁输出

    [root@ansible-server ~]# ansible test -m ping -o
    172.22.69.216 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "ping": "pong"}
    

    -o 选项可以将输出结果放在同一行

    思考:ping模块的原理

    关闭web主机的sshd进程

    [root@ansible-node ~]# systemctl stop sshd
    

    进行ping连通性测试,结果是连接失败

    [root@salt-master tmp]# ansible web -m ping -o
    172.22.69.97 | UNREACHABLE!: Failed to connect to the host via ssh: ssh: connect to host 172.22.69.97 port 22: Connection refused
    

    结论:Ansible的ping模块并不是通过ICMP的ping,而是探测ssh程序是否连接。

  • 相关阅读:
    Javascript异步与同步问题
    promise解决异步问题:.then和async_await的渊源
    vue 爬坑之路----移动端适配rem单位
    vue 爬坑之路---can't resolve 'sass-loader'
    vue-cli新建vue项目
    sublimeT3编译sass.为css到指定的路径。
    禁止滚动条滚动
    让本地的静态html页面在node上跑起来
    地址三联动,简明实现
    关于数组去重
  • 原文地址:https://www.cnblogs.com/ElegantSmile/p/12588792.html
Copyright © 2011-2022 走看看