Ansible-安装 (Centos7 通过Yum安装最新发布版本),ansible-centos7
Ansible-安装 (Centos7 通过Yum安装最新发布版本),ansible-centos7
Ansible-安装 (Centos7 通过Yum安装最新发布版本)
1.环境准备
操作系统:Contos7
Python版本: Python 2.6 或 Python 2.7
2.设置EPEL仓库
通过Yum安装RPMs适用于 EPEL 6, 7。Ansible仓库默认不在yum仓库中,因此我们需要使用下面的命令启用epel仓库
rpm -iUvh http://dl.Fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
3.使用yum安装Ansible
安装 : yum install ansible
[root@localhost myron01]# yum install ansible
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
.......
.......
Installed:
ansible.noarch 0:2.2.1.0-1.el7
Dependency Installed:
PyYAML.x86_64 0:3.10-11.el7 libtomcrypt.x86_64 0:1.17-23.el7
libtommath.x86_64 0:0.42.0-4.el7 libyaml.x86_64 0:0.1.4-11.el7_0
python-babel.noarch 0:0.9.6-8.el7 python-httplib2.noarch 0:0.7.7-3.el7
python-jinja2.noarch 0:2.7.2-2.el7 python-keyczar.noarch 0:0.71c-2.el7
python-markupsafe.x86_64 0:0.11-10.el7 python-six.noarch 0:1.9.0-2.el7
python2-crypto.x86_64 0:2.6.1-13.el7 python2-ecdsa.noarch 0:0.13-4.el7
python2-paramiko.noarch 0:1.16.1-2.el7 python2-pyasn1.noarch 0:0.1.9-7.el7
sshpass.x86_64 0:1.06-1.el7
Complete!
[root@localhost myron01]#
版本检查:ansible –version(两个-)
[root@localhost myron01]# ansible --version
ansible 2.2.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
4.设置用于节点鉴权的SSH密钥
进入~/.ssh生成秘钥 ssh-keygen
[root@localhost ansible]# cd ~/.ssh
[root@localhost .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
5b:ae:1e:90:b9:85:90:f2:0a:c1:ef:e7:88:23:f5:a6 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| |
|. . |
|... o |
| ..o . + |
|. .. = S . |
| .o. + + |
| ..o .. o . |
|... * o |
|..E+ . .o |
+-----------------+
[root@localhost .ssh]#
使用ssh-copy-id命令来复制Ansible公钥到节点中
[root@localhost .ssh]# ssh-copy-id myron@192.168.150.136
The authenticity of host '192.168.150.136 (192.168.150.136)' can't be established.
ECDSA key fingerprint is f6:c2:20:dc:ec:28:71:4a:fe:4d:d9:5d:39:39:65:8f.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
myron@192.168.150.136's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'myron@192.168.150.136'"
and check to make sure that only the key(s) you wanted were added.
[root@localhost .ssh]#
测试免密操作 ansible all -m ping -u myron
[root@localhost .ssh]# ansible all -m ping -u myron
192.168.150.136 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[root@localhost .ssh]#
5.基本功能
Ansible提供两种方式去完成任务,ad-hoc 命令和写 Ansible playbook
//TODO ansible playbook 用例
评论暂时关闭