linux上的ansible

ansible

准备环境,连接xshell,安装yum。

安装ansible

1.安装epel

[root@localhost ~]# yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2.安装python-jinja2-2.7.2-4.el7
在网址下载Python安装包:https://centos.pkgs.org/7/centos-x86_64/python-jinja2-2.7.2-4.el7.noarch.rpm.html

[root@localhost ~]# yum install -y python-jinja2-2.7.2-4.el7.noarch.rpm

3.安装ansible。

[root@localhost ~]# yum install -y ansible

4.检查安装版本。

[root@localhost ~]# ansible --version
ansible 2.9.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

生产公钥/私钥。

[root@localhost ~]#  ssh-keygen -t rsa
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:
b4:81:b2:50:71:7f:37:7d:14:1d:e1:17:76:e0:9c:d2 root@localhost
The key's randomart image is:
+--[ RSA 2048]----+
|    o..       .BB|
|   . . o     =oo+|
|  . . . + . + E.o|
|   . o . + . o ..|
|    .   S        |
|                 |
|                 |
|                 |
|                 |
+-----------------+

默认生成在root家目录.ssh目录下。

[root@localhost ~]# ls -ad .ssh
.ssh

私钥设置,下次登录就不需要密码了。

[root@localhost ~]# ssh-copy-id -i root@192.168.1.145
/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
root@192.168.1.145's password: 
Permission denied, please try again.
root@192.168.1.145's password: 
Permission denied, please try again.
root@192.168.1.145's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.1.145'"
and check to make sure that only the key(s) you wanted were added.

验证登录不需要密码。

[root@localhost ~]# ssh 192.168.1.145
Last login: Sat Dec 28 14:16:25 2019 from 192.168.1.145
[root@bogon ~]# exit           退出
logout
Connection to 192.168.1.145 closed.

编辑配置文件。

[root@localhost ~]# vim /etc/ansible/hosts

在这里插入图片描述
ping自己的组名。

[root@localhost ~]# ansible -m ping "zx"

在这里插入图片描述
验证。

[root@localhost ~]# ansible zx -u root -a ls

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值