Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ssh 从ansible ping ec2实例_Ssh_Amazon Ec2_Ansible - Fatal编程技术网

Ssh 从ansible ping ec2实例

Ssh 从ansible ping ec2实例,ssh,amazon-ec2,ansible,Ssh,Amazon Ec2,Ansible,我有一个正在运行的ec2 amazon linux,我可以使用ssh将其连接到: ssh -i "keypair.pem" ec2-user@some-ip.eu-west-1.compute.amazonaws.com 但当我尝试使用ansible ping服务器时,我得到: testserver | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh.",

我有一个正在运行的ec2 amazon linux,我可以使用ssh将其连接到:

ssh -i "keypair.pem" ec2-user@some-ip.eu-west-1.compute.amazonaws.com
但当我尝试使用ansible ping服务器时,我得到:

testserver | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh.",
    "unreachable": true
}
我正在使用以下主机文件:

testserver ansible_ssh_host=some-ip.eu-west-1.compute.amazonaws.com ansible_ssh_user=ec2-user ansible_ssh_private_key_file=/Users/me/playbook/key-pair.pem
并运行以下命令以运行ansible:

ansible testserver -i hosts -m ping -vvvvv
输出为:

<some-ip.eu-west-1.compute.amazonaws.com> ESTABLISH SSH CONNECTION FOR USER: ec2-user
<some-ip.eu-west-1.compute.amazonaws.com> SSH: ansible.cfg set ssh_args: (-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<some-ip.eu-west-1.compute.amazonaws.com> SSH: ANSIBLE_PRIVATE_KEY_FILE/private_key_file/ansible_ssh_private_key_file set: (-o)(IdentityFile="/Users/me/playbook/key-pair.pem")
<some-ip.eu-west-1.compute.amazonaws.com> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<some-ip.eu-west-1.compute.amazonaws.com> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=ec2-user)
<some-ip.eu-west-1.compute.amazonaws.com> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10)
<some-ip.eu-west-1.compute.amazonaws.com> SSH: PlayContext set ssh_common_args: ()
<some-ip.eu-west-1.compute.amazonaws.com> SSH: PlayContext set ssh_extra_args: ()
<some-ip.eu-west-1.compute.amazonaws.com> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/Users/me/.ansible/cp/ansible-ssh-%h-%p-%r)
<some-ip.eu-west-1.compute.amazonaws.com> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/Users/me/playbook/key-pair.pem"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ec2-user -o ConnectTimeout=10 -o ControlPath=/Users/me/.ansible/cp/ansible-ssh-%h-%p-%r ec2-52-18-106-35.eu-west-1.compute.amazonaws.com '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1462096401.65-214839021792201 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1462096401.65-214839021792201 `" )'"'"''
testserver | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh.",
    "unreachable": true
}
为用户建立SSH连接:ec2用户
SSH:ansible.cfg设置SSH_参数:(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
SSH:ANSIBLE_PRIVATE_KEY_FILE/PRIVATE_KEY_FILE/ANSIBLE_SSH_PRIVATE_KEY_FILE set:(-o)(IdentityFile=“/Users/me/playbook/KEY pair.pem”)
SSH:ansible_密码/ansible_SSH_密码未设置:(-o)(KbdInteractiveAuthentication=no)(PreferredAuthentications=gssapi带麦克风、gssapi-keyex、基于主机、公钥)(PasswordAuthentication=no)
SSH:ANSIBLE_REMOTE_USER/REMOTE_USER/ANSIBLE_USER/USER/-u set:(-o)(USER=ec2 USER)
SSH:ANSIBLE_超时/超时设置:(-o)(ConnectTimeout=10)
SSH:PlayContext集SSH\u公共参数:()
SSH:PlayContext集SSH\u额外参数:()
SSH:仅找到ControlPersist;添加的控制路径:(-o)(控制路径=/Users/me/.ansible/cp/ansible ssh-%h-%p-%r)
SSH:EXEC SSH-C-vvv-o ControlMaster=auto-o ControlPersist=60s-o'IdentityFile=“/Users/me/playbook/key pair.pem”'-o KbdInteractiveAuthentication=no-o PreferredAuthentications=gssapi带麦克风、gssapi-keyex、基于主机、,publickey-o PasswordAuthentication=no-o User=ec2 User-o ConnectTimeout=10-o ControlPath=/Users/me/.ansible/cp/ansible ssh-%h-%p-%r ec2-52-18-106-35.eu-west-1.compute.amazonaws.com'/bin/sh-c''”(umask 22&&mkdir-p“`echo$HOME/.ansible/tmp/ansible-tmp-tmp-1462096401-214839021792201'”&&echo“`echo$HOME/.ansible/tmp/ansible-tmp-1462096401.65-214839021792201`”一词”
testserver |无法访问!=>{
“更改”:错误,
“msg”:“未能通过ssh连接到主机。”,
“遥不可及”:真实
}

我做错了什么?

我遇到了类似的问题,通读帮助了我。具体来说,我正在从Amazon Linux实例ping一个Ubuntu实例,但忘记将连接用户名从“ec2用户”更改为“Ubuntu”!

你必须更改主机文件并确保你有正确的用户名

    test2 ansible_ssh_host=something.something.eu-west-1.compute.amazonaws.com ansible_ssh_user=theUser
“test2”-是我在本地ansible hosts文件中为ssh机制指定的名称

'ansible_ssh_host=something.something.eu-west-1.compute.amazonaws.com'-这是到ec2实例的连接

'ansible\u ssh\u user=theUser'-实例的用户。(重要)

  • 将“ssh”添加到您的实例中
  • [theUser@Instance:]确保将“theUser”复制到主机中,并作为“ansible\u ssh\u user”变量放置
  • 然后尝试ping它


    如果这不起作用,请检查您是否拥有启用amazon aws的ICMP包的权限。

    试试这个解决方案,它对我很有效

    ansible ipaddress  -m ping  -i inventory -u ec2-user
    
    其中inventory是主机文件名

    inventory :    
    [host]
    xx.xx.xx.xx
    [host:vars]
    ansible_user=ec2-user
    ansible_ssh_private_key_file=/location of your pem file/filename.pem
    

    我遇到了这个问题,因为我没有给出我所指的主机文件的位置。

    这就是我的主机文件的外观。 [apache]是我们要安装apache服务器的主机组。 ansible\u ssh\u private\u key\u文件应该是dowloaded.pem文件的路径,以访问您的实例。在我的情况下,两个实例具有相同的凭据

    [apache]
    50.112.133.205 ansible_ssh_user=ubuntu
    54.202.7.87 ansible_ssh_user=ubuntu
    [apache:vars]
    ansible_user=ubuntu
    ansible_ssh_private_key_file=/home/hashimyousaf/Desktop/hashim_key_oregon.pem
    

    你确定你的主机名没有输入错误吗?我无法连接到
    ec2-52-18-106-35.eu-west-1.compute.amazonaws.com
    使用
    ssh
    。是的,确实得到了正确的主机名。它在这里可以公开访问,我只是再次检查了我可以使用上面的地址ssh,你使用的是哪个版本的Ansible?只是想知道,你能从你的机器上ping ec2-52-18-106-35.eu-west-1.compute.amazonaws.com和22上的telnet吗?你已经在你的主机文件中使用了“ec2-52-18-106-35.eu-west-1.compute.amazonaws.com”。我已经重新启动了这个实例,所以我有了一个新地址:这是可以公开访问和ping的,但我不能telnet到它