Amazon web services Ubuntu 16.04LTS中的Ansible配置失败

Amazon web services Ubuntu 16.04LTS中的Ansible配置失败,amazon-web-services,ssh,amazon-ec2,ansible,ubuntu-16.04,Amazon Web Services,Ssh,Amazon Ec2,Ansible,Ubuntu 16.04,我是Devops的新手,我是AWS EC2 Ubuntu 16.04 LTS的初学者,正在学习Ansible 最初我启动了两个EC2实例,SSH端口22在security group中打开,我将实例命名为Master和Slave 当一切都启动并运行时,我ssh'ed进入Master实例。 下面我将逐一列出步骤 1。我创建了一个名为ansible的用户并发布了密码 ubuntu@ip-172-31-17-94:~$ sudo su root@ip-172-31-17-94:/home/u

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

最初我启动了两个EC2实例,SSH端口22在security group中打开,我将实例命名为MasterSlave

当一切都启动并运行时,我ssh'ed进入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] 
root@ip-172-31-17-94:/home/ubuntu# visudo 
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]-----+
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.
2。在/etc/ssh/sshd_config中未注释的permitrotlogin yes和PasswordAuthentication yes并重新启动ssh

3.更改了Visudo文件,向ansible用户添加了root访问权限

 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] 
root@ip-172-31-17-94:/home/ubuntu# visudo 
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]-----+
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.
编辑

  # User privilege specification
root    ALL=(ALL:ALL) ALL
ansible ALL=(ALL:ALL) ALL
保存并关闭

4.生成ssh密钥

 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] 
root@ip-172-31-17-94:/home/ubuntu# visudo 
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]-----+
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.
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'ed在从属服务器中,重复第1、2、3步并注销

8.插入主服务器

local@host $ shh ansible@<Master Ip>
并成功地将配置为无密码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
时,我收到了成功消息

我的问题是如何在从机中安装无代理anible,这是无代理ansible的主要功能


如果我错过了任何步骤,请帮助我。您需要在172.31.29.197上安装Python 2

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