Ubuntu 16.04LTS中的Ansible配置失败

时间:2017-04-22 06:59:07

标签: amazon-web-services ssh amazon-ec2 ansible ubuntu-16.04

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

最初我在安全组中启动了2个打开SSH端口22的EC2实例,我将实例命名为 Master Slave

当所有内容都启动并运行时,我会进入 Master 实例。 我将逐步列出步骤

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@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   .save和关闭

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

8.shh进入 Master 服务器

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.

成功将 Mater 配置为 Slave 无密码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
}

后来,当我gooogled我得到一些块我跟随列出解决方案的步骤。 解决方案是我从 slave 服务器的上面的列表中重复第5步。当从服务器发出ansible -m ping时,我获得成功消息

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

如果我错过任何一步

,请帮助我

1 个答案:

答案 0 :(得分:1)

您需要在172.31.29.197上安装Python 2.

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