一、ansible安装
1、安装第三方epel源
centos 5的epel
#rpm -ivh http://mirrors.sohu.com/fedora-epel/5/x86_64/epel-release-5-4.noarch.rpm
centos 6的epel
#rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
查看系统版本
# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
由于是6版本所以安装6的epel
2、安装ansible
yum install ansible
3、添加主机
# ls /etc/ansible/
其中ansible.cfg是配置文件,hosts是管理主机信息
#cat /etc/ansible/hosts
[test]
172.31.2.16
172.31.2.17
二、ansible应用
1.查看ansible 支持的模块
#ansible-doc -l
2.查看ansible模块的使用方法
#ansible-doc -s xxx
3.实例:批量创建维护账户
# vi useradd.yml
---
- hosts: 172.31.2.17
user: root
sudo: no
vars:
#password: python -c ‘import crypt; print crypt.crypt("devops1232", "fanghanyun")‘
user: fanghanyun
tasks:
- name: add user
action: user name={{ user }} password=faJxjj/6hKXPs update_password=always shell=/bin/bash home=/home/{{ user }}
tags:
- user
4.执行ansible-playbook
#ansible-playbook useradd.yml
本文出自 “hanyun.fang” 博客,请务必保留此出处http://hanyun.blog.51cto.com/1060170/1595646
原文地址:http://hanyun.blog.51cto.com/1060170/1595646