First, installation
1, install third-party Epel source
Epel of CentOS 5
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
Installation of 6 Epel because it is version 6
2, Installation Ansible
yum
install
ansible(ansible主机安装ip:192.168.1.100,下面的hosts里面机器不需要安装,所有执行操作都是在ansible主机完成)
cd /etc/ansible/
[email protected]:
/etc/ansible
# ll
total 12
-rw-r--r-- 1 root root 5113 Dec 29 03:00 ansible.cfg
-rw-r--r-- 1 root root 965 Dec 29 03:00 hosts
其中ansible.cfg是配置文件,hosts是管理主机信息
Cat/etc/ansible/hosts
[CGC]
#ip Port User name password
192.168.1.101 ansible_ssh_port=22 Ansible_ssh_user=root ansible_ssh_pass=123456
3, simple test use
(1) Ping:
Ansible host execution: ansible cgc-m Ping
Results:
192.168.1.101 | Success >> {
"Changed": false,
"Ping": "Pong"
}
proving no problem with the test;
(2) Copy file:
ansible主机执行:ansible cgc -s -m copy -a ‘src=/root/mkdir.sh dest=/home/ mode=755 owner=www group=www‘
192.168.1.101 | Success >> {
"Changed": true,
"Checksum": "ec8295b3b33f8a74b7b7acd98be4870ab6ac1726",
"Dest": "/home/mkdir.sh",
"GID": 500,
"Group": "www",
"Md5sum": "0ed7ccc108ef06e3a95a8006b5d74e54",
"Mode": "0755",
"Owner": "www",
"Size": 29,
"src": "/root/.ansible/tmp/ansible-tmp-1441617257.44-136368933988342/source",
"State": "File",
"UID": 500
}
Check for mkdir.sh files in 192.168.1.101 's home directory.
This article is from the "System website Operations" blog, please be sure to keep this source http://cgc888.blog.51cto.com/3989433/1692415
Ansible installation and simple use