2017-04-22 102 views
1

Im新的Devops和即将学习Ansible作为AWS EC2 Ubuntu 16.04 LTS的初学者。Ubuntu中的Ansible配置失败16.04LTS

最初我都推出2个SSH端口22安全组开放的EC2实例,我命名实例作为

我打成了主人全部启动并运行时的实例。 我将列出步骤逐一跟进

1.我创建了一个叫做用户ansible并发出口令

[email protected]:~$ sudo su 
    [email protected]:/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.取消注释的PermitRootLogin yes和PasswordAuthentication yes把在的/ etc/ssh/sshd_config并重新启动ssh

3.更改Visudo文件添加根访问ansible用户

[email protected]:/home/ubuntu# visudo 

编辑

# User privilege specification 
root ALL=(ALL:ALL) ALL 
ansible ALL=(ALL:ALL) ALL 

保存并关闭

4.Generated SSH密钥生成

[email protected]:~$ 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 [email protected] 
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

[email protected]:~$ 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'ed并重复1,2,3个步骤和注销

8。shh'ed到服务器

[email protected] $ shh [email protected]<Master Ip> 

9.Copying公钥发送至服务器从服务器

[email protected]:~$ 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 
[email protected]'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 


[email protected]:~$ 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 
[email protected]:~$ 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 
} 

后,当我gooogled我得到一些块我跟着列出步骤由该溶液中。 解决方案是我重复第5步从上面的列表奴隶服务器。从服务器发出ansible -m ping当我成功消息

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

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

回答

1

您需要在172.31.29.197安装Python 2。

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