ansible(基础)

Ansible自动化配置管理

1.ansible安装:
ip: 192.168.215.128 (虚拟机)
ip: 47.103.34.26 (aliyun)

2.获取elep源:
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aiyun.com/repo/epel-7.repo

yum install ansible

3. ansible配置文件查找顺序:
$ANSIBLE_CONFIG
ansible.cfg #当目录下
.ansible.cfg #家目录下
/etc/ansible/ansible.cfg #etc下的配置文件


4. 基于密钥的链接:
ssh-keygen #创建密钥
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] #将公钥发送给主机

5. 简单的测试下:
ssh [email protected] #测试是否可以无密码登录

6. Ad-Hoc 的常用模块:

command    #执行shell命令(不支持管道等特殊字符)
shell    #执行shell命令
script    #执行shell脚本
yum仓库    #yum_repository
安装    #yum
配置    #copy
启动    #service , systemd
联网下载    #get_url
创建用户与组    #user,group
授权    #file
定时任务    #crond
挂载    #mount    
firewalld , selinux    #firewall selinx

7. ansible 如何查看帮助文档:
[root@centos7 ~]# ansible-doc -l #查看所有文档
[root@centos7 ~]# ansible-doc yum #查看某个模块的用法

8. command命令模块不支持重定向或管道
#默认模块, 执行命令
[root@centos7 ~]# ansible webservers -a "touch /root/file"

9. 如果需要一些管道操作,则使用shell
[root@centos7 ~]# ansible webservers -m shell -a "ls /root/file"

猜你喜欢

转载自www.cnblogs.com/gukai/p/10799830.html