a2005147 发表于 2018-7-31 06:00:58

Ansible部署及使用

# ansible all -a 'uptime' #all所有节点, -a用于指定命令,‘uptime’执行的命令,如果命令有参数一定要用引号;ansible默认使用command模块,所以可以不用指定。  
10.0.0.130 | success | rc=0 >>
  
11:31:50 up2:01,1 user,load average: 0.00, 0.00, 0.00
  
10.0.0.129 | success | rc=0 >>
  
11:31:50 up2:02,1 user,load average: 0.00, 0.00, 0.00
  
10.0.0.128 | success | rc=0 >>
  
11:31:50 up2:05,1 user,load average: 0.00, 0.00, 0.00
  

  
# ansible-doc -l #查看ansible的所有模块
  
acl                  Sets and retrieves file ACL information.
  
add_host             add a host (and alternatively a group) to the ansible-playbo
  
airbrake_deploymentNotify airbrake about app deployments
  
apt                  Manages apt-packages
  

  
# ansible-doc yum #查看指定模块的文档
  
> YUM
  

  
Installs, upgrade, removes, and lists packages and groups with the
  
`yum' package manager.
  

  
# ansible all -m yum -a "name=httpd state=present" #用yum模块给各节点安装httpd。name指定安装包名,state指定动作:安装可以用present和latest,卸载使用absent。
  
10.0.0.128 | success >> {
  
    "changed": false,
  
    "msg": "",
  
    "rc": 0,
  
    "results": [
  
      "httpd-2.2.15-30.el6.centos.x86_64 providing httpd is already installed"
  
    ]
  
}
  

  
10.0.0.130 | success >> {
  
    "changed": false,
  
    "msg": "",
  
    "rc": 0,
  
    "results": [
  
      "httpd-2.2.15-30.el6.centos.x86_64 providing httpd is already installed"
  
    ]
  
}
  

  
10.0.0.129 | success >> {
  
    "changed": false,
  
    "msg": "",
  
    "rc": 0,
  
    "results": [
  
      "httpd-2.2.15-30.el6.centos.x86_64 providing httpd is already installed"
  
    ]
  
}
页: [1]
查看完整版本: Ansible部署及使用