一;

1、安装ansible

# yum install ansible -y

(可以更新下epel yum源/python2.6 之以上)

# wget http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

# rpm -ivh pel-release-6-8.noarch.rpm

2、安装验证;

二;

1、配置主机(免密码登录)

第一种直接在ansible 直接远程node主机;

第二种复制node的私钥 /root/.ssh/id_rsa.pub 到 ansible的/root/.ssh/authorized_keys 中;

2、配置定义Host Inventory  

# cat /etc/ansible/hosts 

hosts  下是两台node主机;

ansible_ssh_user=root 是ssh登陆用户  

ansible_ssh_pass=guoting 是ssh登陆密码 

三、测试模块;

1、验证node 时间;

# ansible hosts -m command -a 'date'

2、验证主机的基本信息;

查看主机;

# ansible hosts -m command -a "cat /etc/hosts"

查看服务器的基本信息;

# ansible hosts -m setup

3、验证查看配置文件;

查看网络配置文件;

# ansible hosts -m command -a "ls -al /etc/resolv.conf"

4、拷贝文件;

在ansible 创建一个 sh 文件。然后分发到node服务器上;

vi /opt/7.sh

[root@Ansible ~]# cat /opt/7.sh 

#!/bin/bash

let A=1

let B=2

echo $[$A+$B]

文件分发:

# ansible hosts -m copy -a "src =/opt/* dest=/opt/*.sh owner=root group=root mode=0755"

5、测试执行7.sh

执行shell命令;

# ansible hosts -m shell -a "/opt/*.sh"

6、管道命令  raw 模块验证?

验证网路模块;

# ansible hosts -m raw -a 'ifconfig |grep eth0'

[root@Ansible ~]# ansible hosts -m raw -a 'ifconfig | grep eth0'

7、检验其他实例;

网络监测

# ansible all -m ping -u root

shell输出;

# ansible all -a "/bin/echo hello"

设置权限;

# ansible hosts -m raw -a "chmod 755 /opt/*"

拷贝文件;

# ansible hosts -m copy -a "src=jre-8u91-linux-x64.tar.gz dest=/opt/"

+

+

+

( Ansible 使用笔记 + + +