IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    自动化运维ansible学习笔记

    建伟发表于 2023-10-27 06:15:18
    love 0

    #安装ansible
    yum -y install ansible

    #编辑ansible主机清单
    vim /etc/ansible/hosts

    #生成密钥对
    ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ''

    #同步ssh密钥
    ssh-copy-id 192.168.12.12 -p 22

    #连接ssh
    ssh 192.168.12.12 -p 22

    #执行ping命令
    ansible 192.168.12.12 -m ping

    [WARNING]: Platform linux on host 192.168.12.12 is using the discovered Python
    interpreter at /usr/bin/python3.5, but future installation of another Python
    interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_
    appendices/interpreter_discovery.html for more information.
    192.168.12.12 | SUCCESS => {
    "ansible_facts": {
    "discovered_interpreter_python": "/usr/bin/python3.5"
    },
    "changed": false,
    "ping": "pong"
    }

    #同步hosts文件
    [root@localhost ~]# ansible 192.168.12.12 -m copy -a "src=/etc/hosts dest=/etc/hosts"

    [WARNING]: Platform linux on host 192.168.12.12 is using the discovered Python
    interpreter at /usr/bin/python3.5, but future installation of another Python
    interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_
    appendices/interpreter_discovery.html for more information.
    192.168.12.12 | CHANGED => {
    "ansible_facts": {
    "discovered_interpreter_python": "/usr/bin/python3.5"
    },
    "changed": true,
    "checksum": "c200e5c586e263c00abed391f130ea016e4fe2a3",
    "dest": "/etc/hosts",
    "gid": 0,
    "group": "root",
    "md5sum": "e79557ef0184c8e2b887e1e6d9b8ed1a",
    "mode": "0644",
    "owner": "root",
    "size": 181,
    "src": "/root/.ansible/tmp/ansible-tmp-1698389078.95-103802-108612348163014/source",
    "state": "file",
    "uid": 0
    }



沪ICP备19023445号-2号
友情链接