ansible简单安装及拉取文件

不想你离开。 提交于 2020-09-30 19:42:23

yum源:
[root@jack7-1 yum.repos.d]# cat ali*
[aliBase]
name=aliBase
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-$releasever
[aliEpel]
name=aliEpel
baseurl=https://mirrors.aliyun.com/epel/$releasever\Server/$basearch/
enabled=1
gpgcheck=0











直接yum安装:yum install -y ansible

配置额客户端的连接信息:
[root@jack7-1 yum.repos.d]# tail -6 /etc/ansible/hosts
all:
hosts:
192.168.179.137: #主机IP
jack6-2: #主机别名
ansible_host: 192.168.179.137 #别名对应的主机
ansible_ssh_port: 22 #ssh通讯的端口






 这边做了双机互信:
 ssh-keygen
 ssh-copy-id  -i  root@jack6-2

 检测通讯情况:
 ansible  jack6-2  -m ping

 由此可以看出:-m  是调用模块的功能

 从jack6-2主机拉取文件,注意只能是文件哦,目录不行的哦
 ansible-doc   -s   fetch   查看用法

 ansible  jack6-2  -m   fetch   -a  "src=/backup/2020-08-28.tar.gz dest=/root/"

 # 拉取结果如下
 └── jack6-2
└── backup
    └── 2020-08-28.tar.gz

会显示从哪个主机拉取的,而且由于幂等性原则,再次拉取,如果文件没有变化是不会再次拉取 的

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!