介绍:
1、基于python语言开发,自动化运维工具
2、实现IT基础设施设备进行批量管控
特性:
1、开源的、跨平台的
2、底层基于ssh协议通信
3、no server
4、no agent
5、支持playbook剧本
6、提供API接口
# vi /etc/ansible/ansibe.cfg
host_key_checking = false
:wq
# vi /etc/ansible/hosts
[aa]
10.0.1.1 ansible_ssh_user=root ansible_ssh_pass=xxxx ansible_ssh_port=22
:wq
Ansible AD HOC(命令行调用模块)
ansible <被管理机> -m <模块名> -a <模块参数>
shell模块(执行命令)
ansible aa -m shell -a "free -m"
copy模块(推送文件)
ansible aa -m copy -a 'src=file01 dest=/tmp'
fetch模块(拉取文件)
ansible aa -m fetch -a 'src=/etc/hosts dest=./'
file模块(管理文件目录)
ansible aa -m file -a 'path=/tmp/file01 state=absent' (absent为删除)
cron模块(计划任务)
ansible aa -m cron -a 'name=TimeSync minute=*/30 job=/usr/sbin/ntpdate ntp.aliyuncom &> /dev/null'
ansible aa -m shell -a 'crontab -l'
yum模块(管理rpm软件)
ansible aa -m yum -a 'name=vsftpd '
service模块(系统服务,enabled表示开机自起)
ansible aa -m service -a 'name=vsftpd state=started enabled=yes'
lineinfile模块(往文件追加内容)
setup模块(搜集被管理机的状态信息,ip、主机名、系统版本、内存、CPU型号等)
ansible aa -m setup