ansible学习之--ansible初探,ansible--ansible


ansible 技术相关(自动化运维工具) 是基于python开发的

安装方式有 yum,apt,pip等

例如使用pip:pip install ansible

ansible对于客户端的唯一要求就是需要有SSH和Python(如果python版本过低则需要安装python-simplejson module)


最简单的一条ansible命令:

ansible -i /etc/ansible/hosts all -m command  -a 'date' -u prod


参数:

-i 指定hosts文件的位置,hosts是yaml文件,all表示hosts文件中的所有的组

-m 指定ansible的module,这里的command表示ansible的command模块,还有很多其他的模块例如shell

-a 指定args参数

-u 指定用户(因为这里是基于SSH认证的)


ansible常用命令:

ansible  #执行简单的临时命令 (ad-hoc命令)

ansible-playbook  #执行playbook,playbook是yaml文件 (作为配置管理工具的主要功能)

ansible-doc  #查询ansible module文档

例子:

---
- hosts: cmdb
  user: prod
  sudo: True
  tasks:
   - name: show the date
     shell: date
     notify: show1
  handlers:
   - name: show1
     shell: ls

执行ansible-playbook user.yml

user.yml文件中

hosts:指定设备组

user:指定ssh用户

sudo:是否使用sudo权限

tasks:关键词指明执行动作

name:给动作命名

yum:ansible指定模块

相关内容

    暂无相关文章