
Ansible을 사용하여 퍼블릭 IP 주소가 없는 AWS 호스트에 배포하려고 합니다. 점프 상자에 SSH를 통해 수동으로 호스트에 연결할 수 있고 해당 상자에서 다음과 같은 개인 컴퓨터에 SSH를 통해 연결할 수 있습니다.my machine-->bastion-->private server
이 플레이북은 다른 플레이와 공유되는 역할을 사용하기 때문에 Ansible 네이티브 지원을 사용할 수 없을 것 같습니다. 이러한 역할은 특정 인벤토리 그룹에 의존합니다. 설정하면 group_vars
AWS가 아닌 인프라에 배포하기 위한 플레이북이 중단됩니다.
내 SSH 구성 파일은 다음과 같습니다.
# Servers in availability zone A
Host 10.0.0.*
ProxyCommand ssh -W %h:%p bastion.example.com
IdentityFile ~/.ssh/key.pem
# Servers in availability zone B
Host 10.0.1.*
ProxyCommand ssh -W %h:%p bastion.example.com
IdentityFile ~/.ssh/key.pem
# The bastion host itself
Host bastion.example.com
User ubuntu
IdentityFile ~/.ssh/key.pem
ControlMaster auto
ControlPath ~/.ssh/ansible-%r@%h:%p
ControlPersist 5m
배스천 서버와 개인 서버의 키는 동일합니다.
시도하면 ssh 10.0.0.175 -F /tmp/aws_bastion_ssh_config -vvv
다음과 같은 결과가 나타납니다.
(venv) andrew@dell:~/projects/ansible-playbooks$ ssh 10.0.0.175 -F /tmp/aws_bastion_ssh_config -vvv
OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /tmp/aws_bastion_ssh_config
debug1: /tmp/aws_bastion_ssh_config line 6: Applying options for 10.0.0.*
debug1: Executing proxy command: exec ssh -W 10.0.0.175:22 bastion.example.com
debug1: permanently_drop_suid: 1000
debug1: key_load_public: No such file or directory
debug1: identity file /home/andrew/.ssh/key.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/andrew/.ssh/key.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
Permission denied (publickey).
ssh_exchange_identification: Connection closed by remote host
어떻게 하면 작동하게 할 수 있나요?
점프박스에 열쇠가 있어야 합니까? 어떻게 구성하나요?
ssh bastion.example.com -F /tmp/aws_bastion_ssh_config
편집: 추가 정보:- 요새 서버에 연결할 때 점프 상자에서 개인 컴퓨터에 연결할 수 있음을 명확히 하기 위해 . 해당 서버에 키를 복사하고 개인 컴퓨터에 연결할 때. 이상적으로는 점프 박스에 키를 두지 않는 것을 선호합니다. 네트워킹이 올바르게 실행되는지 확인하기 위해 키를 거기에 두었습니다.ssh [email protected] -i ~/.ssh/key.pem
답변1
ProxyCommand로 수행하는 작업은 완전히 별개인 두 개의 SSH 명령을 시작하는 것입니다.
- 이는 프록시를 사용하여 10.0.0.175에 인증하려고 하므로 배스천에 키와 구성이 필요하지 않습니다.
- 요새에 인증할 수만 있으면 되는 프록시를 제공하는 것입니다.
1.에 대한 명령은 제대로 작동하지만 2에 대한 디버그 출력이 표시되지 않습니다. 해결 가능한 TLD를 사용했고 그 밖의 모든 것은 일반적인 구성이므로 2. 오류가 발생하지 않지만 원하는 작업을 수행하지 않습니다. 구성에서 IdentityFile
및 옵션이 제공되지 않았습니다 . User
다른 키나 사용자로 인증하고 요새에 의해 거부됩니다(당연히 그렇습니다).
2. 또한 구성을 읽도록 하려면 다음과 같이 해당 옵션을 명시적으로 전달하십시오.
# Servers in availability zone A
Host 10.0.0.*
ProxyCommand ssh -vvv -F /tmp/aws_bastion_ssh_config -W %h:%p bastion.example.com
IdentityFile ~/.ssh/key.pem
# Servers in availability zone B
Host 10.0.1.*
ProxyCommand ssh -vvv -F /tmp/aws_bastion_ssh_config -W %h:%p bastion.example.com
IdentityFile ~/.ssh/key.pem
# The bastion host itself
Host bastion.example.com
User ubuntu
IdentityFile ~/.ssh/key.pem
ControlMaster auto
ControlPath ~/.ssh/ansible-%r@%h:%p
ControlPersist 5m
그리고 모든 것이 작동해야 합니다. 다음으로 확인하세요.
ssh -vvv -F /tmp/aws_bastion_ssh_config 10.0.0.175
그런 다음 1과 2의 양식을 모두 제거합니다 . 기본 위치로 -vvv
이동하면 두 옵션 모두 제거될 수 있습니다(그리고 ssh는/tmp/aws_bastion_ssh_config
-F
/etc/ssh/ssh_config
그리고 ~/.ssh/config files
)