https://github.com/zq2599/blog_demos
内容:所有原创文章分类汇总及配套源码,涉及Java、Docker、Kubernetes、DevOPS等;
ansible是常用的开源配置管理工具,简单易用,可以高效的帮助我们对服务器进行远程操作,下图来自ansible官网,可见一台安装了ansible的机器可以远程控制亚马逊的EC2、S3服务器:
官方文档:https://docs.ansible.com
hostname | IP地址 | 作用 |
---|---|---|
ansible | 192.168.133.160 | 装了ansible,在此机器执行ansible命令操作cdh002机器 |
cdh002 | 192.168.133.162 | 从ansible机器上,通过ansible命令和脚本,操作cdh002 |
yum install -y ansible
[root@ansible playbooks]# ansible --version
ansible 2.4.2.0
config file = /root/playbooks/ansible.cfg
configured module search path = [u‘/root/.ansible/plugins/modules‘, u‘/usr/share/ansible/plugins/modules‘]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
安装成功,接下来开始体验;
[cdh-group]
cdh002 ansible_host=192.168.133.162 ansible_port=22 ansible_user=root ansible_password=888888
[defaults]
inventory = ~/playbooks/hosts
host_key_checking = False
[root@centos7 playbooks]# ansible cdh002 -m command -a "free -m"
cdh002 | SUCCESS | rc=0 >>
total used free shared buff/cache available
Mem: 15866 9047 3674 21 3145 6500
Swap: 2047 0 2047
[root@centos7 playbooks]# ansible cdh002 -a "free -m"
cdh002 | SUCCESS | rc=0 >>
total used free shared buff/cache available
Mem: 15866 9066 3648 21 3151 6480
Swap: 2047 0 2047
- name: test cdh-group
hosts: cdh-group
gather_facts: True
tasks:
- debug: var=ansible_distribution
- name: install redhat-lsb
yum: name=redhat-lsb state=present
ansible支持丰富的命令,参考官方文档:https://docs.ansible.com/ansible/latest/modules/modules_by_category.html
至此,ansible2.4版本安装和体验都完成了,如果您想尝试ansible,希望本文能给您一些参考
微信搜索「程序员欣宸」,我是欣宸,期待与您一同畅游Java世界...
https://github.com/zq2599/blog_demos
原文:https://www.cnblogs.com/bolingcavalry/p/13824192.html