我是 Devops 的新手,我作为 AWS EC2 Ubuntu 16.04 LTS 的初学者正在学习 Ansible。

最初我在安全组中启动了 2 个 SSH 端口 22 打开的 EC2 实例,我将这些实例命名为 大师 奴隶 .

我 ssh 进入 大师 一切都启动并运行时的实例。
我将一一列出以下步骤

1.我创建了一个名为ansible的用户,并下发了密码

 ubuntu@ip-172-31-17-94:~$ sudo su 
    root@ip-172-31-17-94:/home/ubuntu# adduser ansible  
Adding user `ansible' ... 
Adding new group `ansible' (1001) ... 
Adding new user `ansible' (1001) with group `ansible' ... 
Creating home directory `/home/ansible' ... 
Copying files from `/etc/skel' ... 
Enter new UNIX password:  
Retype new UNIX password:  
passwd: password updated successfully 
Changing the user information for ansible 
Enter the new value, or press ENTER for the default 
    Full Name []:  
    Room Number []:  
    Work Phone []:  
    Home Phone []:  
    Other []:  
Is the information correct? [Y/n]  

2.在/etc/ssh/sshd_config中取消注释PermitRootLogin yes和PasswordAuthentication yes并重启ssh

3.修改Visudo文件,增加ansible用户的root权限
root@ip-172-31-17-94:/home/ubuntu# visudo  

已编辑
  # User privilege specification 
root    ALL=(ALL:ALL) ALL 
ansible ALL=(ALL:ALL) ALL 

保存并关闭

4.生成ssh keygen
ansible@ip-172-31-17-94:~$ ssh-keygen -t rsa -b 4096  
Generating public/private rsa key pair. 
Enter file in which to save the key (/home/ansible/.ssh/id_rsa):  
Created directory '/home/ansible/.ssh'. 
Enter passphrase (empty for no passphrase):  
Enter same passphrase again:  
Your identification has been saved in /home/ansible/.ssh/id_rsa. 
Your public key has been saved in /home/ansible/.ssh/id_rsa.pub. 
The key fingerprint is: 
SHA256:wah0yD9Ngf7hzLIihkEFvNYjPNrzcLubNxGnqFKYrik ansible@ip-172-31-17-94 
The key's randomart image is: 
+---[RSA 4096]----+ 
|...    ..        | 
| . o ..o .       | 
|. + +.o +        | 
| B + +ooo.       | 
|++o o.oOS.       | 
|= = o +.=        | 
|.+ * . +         | 
|Eo+ +.+          | 
|=o .+= .         | 
+----[SHA256]-----+ 

5. 安装 Ansible 包
$ sudo apt-get install software-properties-common 
$ sudo apt-add-repository ppa:ansible/ansible 
$ sudo apt-get update 
$ sudo apt-get install ansible 

太棒了!...一切就绪,ansible 已安装在主服务器中
我发出了一个命令来测试 ansible
ansible@ip-172-31-17-94:~$ ansible --version  
ansible 2.3.0.0 
  config file = /etc/ansible/ansible.cfg 
  configured module search path = Default w/o overrides 
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] 

6. 编辑/etc/ansible/hosts 并添加我的从属服务器私有(private) IP(我的 ec2 在同一个可用区的同一个子网中)所以我使用私有(private) IP

[my]

172.31.29.197 .save and closed



7.ssh'ed 在从服务器中并重复 1、2、3 步骤并注销

8.shh'ed到主服务器
local@host $ shh ansible@<Master Ip> 

9.从主服务器复制公钥到从服务器
ansible@ip-172-31-17-94:~$ ssh-copy-id 172.31.29.197 
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ansible/.ssh/id_rsa.pub" 
The authenticity of host '172.31.29.197 (172.31.29.197)' can't be established. 
ECDSA key fingerprint is SHA256:qOW0ZktetcpTNmxRsubxn1kcr8egyNmcA5Uk9+oWc7A. 
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 
ansible@172.31.29.197's password:  
 
Number of key(s) added: 1 
 
Now try logging into the machine, with:   "ssh '172.31.29.197'" 
and check to make sure that only the key(s) you wanted were added  
 
 
ansible@ip-172-31-17-94:~$ ssh 172.31.29.197 
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-1013-aws x86_64) 
 
 * Documentation:  https://help.ubuntu.com 
 * Management:     https://landscape.canonical.com 
 * Support:        https://ubuntu.com/advantage 
 
  Get cloud support with Ubuntu Advantage Cloud Guest: 
    http://www.ubuntu.com/business/services/cloud 
 
14 packages can be updated. 
12 updates are security updates. 
 
 
Last login: Sat Apr 22 06:27:15 2017 from 42.109.141.238 
ansible@ip-172-31-29-197:~$ logout 
Connection to 172.31.29.197 closed. 

并成功配置 母校 奴隶 无密码 ssh 连接

到那时我还没有遇到任何问题。
当我发出命令 Ansible -m ping all我有一个错误
172.31.29.197 | FAILED! => { 
    "changed": false,  
    "failed": true,  
    "module_stderr": "Shared connection to 172.31.29.197 closed.\r\n",  
    "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",  
    "msg": "MODULE FAILURE",  
    "rc": 0 
} 

后来当我用谷歌搜索时,我得到了一些我按照解决方案列出的步骤。
解决方案是我重复 第 5 步 来自 中的上述列表奴隶 服务器。发布时 ansible -m ping来自 大师 我得到的服务器 成功留言

我的问题是如何在 Slave 中安装无代理 anible,ansible 无代理的主要特点!

如果我错过了任何步骤,请帮助我

请您参考如下方法:

您需要在 172.31.29.197 上安装 Python 2。

或者(在不太可能的情况下)如果它安装在不同于 /usr/bin/python 的路径中您需要添加 ansible_python_interpreter指向库存文件的正确可执行文件的参数。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!