python ansible后台批处理

官网
当前这个只能支持linux机器作为主机。
主页

安装

在centos中安装:

sudo yum install ansible -y
sudo pip install paramiko PyYAML Jinja2 httplib2 six

ubuntu安装:

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible -y
sudo pip install paramiko PyYAML Jinja2 httplib2 six

配置自己的hosts文件

$ echo "127.0.0.1" > ~/ansible_hosts
$ export ANSIBLE_HOSTS=~/ansible_hosts
[cq]
gs1 ansible_ssh_user=cq ansible_ssh_host=39.106.154.40
gs2 ansible_ssh_user=cq ansible_ssh_host=47.93.13.164
gs3 ansible_ssh_user=cq ansible_ssh_host=101.200.55.213
[local]
sss2 ansible_ssh_user=zqj ansible_ssh_host=192.168.22.223
sss3 ansible_ssh_user=zqj ansible_ssh_host=192.168.22.225
sss4 ansible_ssh_user=zqj ansible_ssh_host=192.168.22.224

拷贝文件

ansible-doc -s copy
ansible [dst_name] -m copy -a 'src=httpd.conf dest=/tmp/ owner=root group=root mode=644 backup=yes'

参考文档

发布了76 篇原创文章 · 获赞 13 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/erlang_hell/article/details/104259604