• ansible安装及快速应用


    1 安装epel源

    yum install -y epel-release
    
    • 1

    2 安装ansible

    yum install -y ansible
    
    • 1

    3 备份hosts文件

    cp -p /etc/ansible/hosts /etc/ansible/hosts.bak
    echo "#" > /etc/ansible/hosts
    
    • 1
    • 2

    4 编辑/etc/ansible/hosts文件

    [k8s-master01]
    192.168.3.81 ansible_ssh_user=root ansible_ssh_pass=21vianet ansible_ssh_port=22
    
    • 1
    • 2

    5 先手动ssh,不用输入密码退出

     ssh 192.168.3.81
    The authenticity of host '192.168.3.81 (192.168.3.81)' can't be established.
    ECDSA key fingerprint is SHA256:md9mvpbrZ+mgkRx4OHTQKI2EOqjJQUGjWeiaoRCsI3k.
    ECDSA key fingerprint is MD5:38:6d:b1:dd:82:32:47:f7:9c:8b:5b:eb:1d:b1:28:bd.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '192.168.3.81' (ECDSA) to the list of known hosts.
    root@192.168.3.81's password: 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    5 执行ping模块

    # ansible -i /etc/ansible/hosts k8s-master01 -m ping
    [WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
    192.168.3.81 | SUCCESS => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": false, 
        "ping": "pong"
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    6 执行shell命令

    # ansible -i /etc/ansible/hosts all -m shell -a "cat /etc/hosts"
    [WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
    192.168.3.81 | CHANGED | rc=0 >>
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    192.168.3.81 k8s-master
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    7 执行copy模块

    # ansible -i /etc/ansible/hosts all -m copy -a 'src=/etc/passwd dest=/tmp/passwd force=yes backup=yes'
    [WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
    192.168.3.81 | CHANGED => {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        }, 
        "changed": true, 
        "checksum": "28d6e8e018458778ff571982da7f075c6b00064b", 
        "dest": "/tmp/passwd", 
        "gid": 0, 
        "group": "root", 
        "md5sum": "28391a2a51a52406b752bd81fab47ee1", 
        "mode": "0644", 
        "owner": "root", 
        "size": 895, 
        "src": "/root/.ansible/tmp/ansible-tmp-1661655079.71-34248-166099024075536/source", 
        "state": "file", 
        "uid": 0
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    ansible -i /etc/ansible/hosts all -m copy -a ‘src=/etc/passwd dest=/tmp/passwd force=yes backup=yes’

  • 相关阅读:
    UDPNM测试技术分享
    STM32F407 2个高级定时器生成2路无刷电机波形以及相电流采集程序(寄存器版)
    Git 详细安装教程(详解 Git 安装过程的每一个步骤)
    P1226 【模板】快速幂
    spring复习(第二天上午)(黑马版)
    穿越障碍:最小路径和的高效算法比较【python力扣题64】
    springboot日志切面记录请求日志
    前端国内镜像环境安装网址
    怎么给视频去水印?手把手教你去水印
    [Docker]二.Docker 镜像,仓库,容器介绍以及详解
  • 原文地址:https://blog.csdn.net/cloud_engineer/article/details/126567455