Ansible 配置在 Ubuntu 16.04LTS 中失败



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

最初,我已经启动了 2 个 EC2 实例,并在安全组中打开了 SSH 端口 22,我将这些实例命名为主实例和从实例

当一切启动并运行时,我进入了主实例。 我将逐一列出步骤如下

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注册机

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并添加了我的从属服务器私有 IP(我的 ec2 位于同一可用区的同一子网中),所以我使用了私有 IP

[我的]

172.31.29.197 .保存并关闭

7.在从属服务器中ssh并重复1,2,3步骤并注销

8.进入服务器

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.

并成功配置了MaterSlave的无密码ssh连接

在那之前,我没有遇到任何问题。 当我发出命令时Ansible -m ping all我收到错误

172.31.29.197 | FAILED! => {
"changed": false, 
"failed": true, 
"module_stderr": "Shared connection to 172.31.29.197 closed.rn", 
"module_stdout": "/bin/sh: 1: /usr/bin/python: not foundrn", 
"msg": "MODULE FAILURE", 
"rc": 0
}

后来当我谷歌搜索时,我得到了一些块,我按照解决方案的步骤列出。 解决方案是我在从属服务器中重复上述列表中的步骤5。从服务器发出ansible -m ping时,我得到了成功消息

我的问题是如何在从站中安装无代理的,代理的主要功能!

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

您需要在 172.31.29.197 上安装 Python 2。

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

最新更新