ansible模块+ssh免密+playbook剧本笔记
ansible使用
ssh免密登录
一台pc上ansible安装
配置vim /etc/ansible/hosts
[webservers]
#另一台主机IP,#也可以对自己进行免密登录
192.168.116.129
每台主机上:ssh-******
进入目录:cd .ssh/
创建:ssh-copy-id [email protected]
登录:ssh [email protected]
查看是否免密成功:ansible all -m ping
-a后面跟命令 用‘’单引号
[[email protected] ~]# ansible webservers -a 'touch ~/abc.doc'
[WARNING]: Consider using file module with state=touch rather than running touch
192.168.116.129 | SUCCESS | rc=0 >>
192.168.116.128 | SUCCESS | rc=0 >>
ansible模块学习(实现两台pc文件的操作等)
ssh免密登录
一台pc上ansible安装
配置vim /etc/ansible/hosts
[webservers]
#另一台主机IP,#也可以对自己进行免密登录
192.168.116.129
每台主机上:ssh-******
进入目录:cd .ssh/
创建:ssh-copy-id [email protected]
登录:ssh [email protected]
查看是否免密成功:ansible all -m ping
-a后面跟命令 用‘’单引号
[[email protected] ~]# ansible webservers -a 'touch ~/abc.doc'
[WARNING]: Consider using file module with state=touch rather than running touch
192.168.116.129 | SUCCESS | rc=0 >>
192.168.116.128 | SUCCESS | rc=0 >>
ansible模块学习(实现两台pc文件的操作等)
http://blog.****.net/iloveyin/article/details/46982023
剧本playbook(格式特别重要)
vim test.yml
---
- hosts: webservers #指定远程任务的主机
remote_user: root #在远程主机上以root角色执行
tasks: #任务列表
- name: test connect
ping:
...
执行剧本
ansible-playbook test.yml