现在的位置: 首页 > Linux > 正文
自动化运维ansible学习笔记
2023年10月27日 Linux, 自动化运维 ⁄ 共 1352字 暂无评论

#安装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
}

建伟

给我留言

留言无头像?



×