【发布时间】:2021-08-11 00:48:35
【问题描述】:
任何人都可以得到 ansible 的:ansible_connection: aws_ssm 工作?
AFAICT 这应该是 ssh 的替代品: https://docs.ansible.com/ansible/latest/collections/community/aws/aws_ssm_connection.html
我的剧本使用 ssh 运行,但不是 ssm:
---
- name: Test command
gather_facts: false
hosts: all
vars:
ansible_connection: ssh
# ansible_connection: aws_ssm <--- this one no worky
ansible_aws_ssm_region: eu-central-1
tasks:
- name: test
command:
cmd: ls -l
运行使用:
ansible-playbook -i inventory_aws_ec2.yml --limit nghc-sbox2-bastion test.yml -vvvv
我在 ansible SSM 配置中遗漏了一些东西。错误是:(来自/var/log/amazon/ssm/amazon-ssm-agent.log)
2021-08-10 23:48:51 信息 [ssm-session-worker] [bruce.edge@xxx.com-04d88576fd5ec3ae7] [DataBackend] [pluginName=Standard_Stream] 发起握手 2021-08-10 23:48:54 错误 [ssm-session-worker] [bruce.edge@xxx.com-04d88576fd5ec3ae7] [DataBackend] [pluginName=Standard_Stream] 获取数据密钥失败: 无法检索数据密钥,解密数据密钥时出错 AccessDeniedException:密文指的是客户主密钥 不存在,在这个区域不存在,或者你不存在 允许访问。
ansible 输出不再有用:
<i-0c208bc6d31fa6bf1> EXEC stdout line:
<i-0c208bc6d31fa6bf1> EXEC stdout line: Starting session with SessionId: bruce.edge@xxx.com-0f7b6c9323afa74bc
<i-0c208bc6d31fa6bf1> EXEC remaining: 60
<i-0c208bc6d31fa6bf1> EXEC remaining: 59
<i-0c208bc6d31fa6bf1> EXEC stdout line:
<i-0c208bc6d31fa6bf1> EXEC stdout line:
<i-0c208bc6d31fa6bf1> EXEC stdout line: SessionId: bruce.edge@xxx.com-0f7b6c9323afa74bc :
<i-0c208bc6d31fa6bf1> EXEC stdout line: ----------ERROR-------
<i-0c208bc6d31fa6bf1> EXEC stdout line: Encountered error while initiating handshake. Fetching data key failed: Unable to retrieve data key, Error when decrypting data key AccessDeniedException: The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access.
<i-0c208bc6d31fa6bf1> EXEC stdout line: status code: 400, request id: 53549e47-03a1-4a1f-8f30-8f0c27482cc5
<i-0c208bc6d31fa6bf1> EXEC stdout line:
<i-0c208bc6d31fa6bf1> EXEC stdout line:
<i-0c208bc6d31fa6bf1> ssm_retry: attempt: 0, caught exception(local variable 'returncode' referenced before assignment) from cmd (echo ~...), pausing for 0 seconds
<i-0c208bc6d31fa6bf1> CLOSING SSM CONNECTION TO: i-0c208bc6d31fa6bf1
<i-0c208bc6d31fa6bf1> TERMINATE SSM SESSION: bruce.edge@xxx.com-0f7b6c9323afa74bc
<i-0c208bc6d31fa6bf1> ESTABLISH SSM CONNECTION TO: i-0c208bc6d31fa6bf1
<i-0c208bc6d31fa6bf1> SSM COMMAND: ['/usr/local/bin/session-manager-plugin', '{"SessionId": "bruce.edge@xxx.com-0d95f1030d63fa155", "TokenValue": "......Gsoj8bEu3d9s=", "StreamUrl": "wss://ssmmessages.eu-central-1.amazonaws.com/v1/data-channel/bruce.edge@xxx.com-0d95f1030d63fa155?role=publish_subscribe", "ResponseMetadata": {"RequestId": "8d20fbe9-d3d2-44e7-a832-a1d4d86861a9", "HTTPStatusCode": 200, "HTTPHeaders": {"server": "Server", "date": "Wed, 11 Aug 2021 00:43:13 GMT", "content-type": "application/x-amz-json-1.1", "content-length": "651", "connection": "keep-alive", "x-amzn-requestid": "8d20fbe9-d3d2-44e7-a832-a1d4d86861a9"}, "RetryAttempts": 0}}', 'eu-central-1', 'StartSession', '', '{"Target": "i-0c208bc6d31fa6bf1"}', 'https://ssm.eu-central-1.amazonaws.com']
<i-0c208bc6d31fa6bf1> SSM CONNECTION ID: bruce.edge@xxx.com-0d95f1030d63fa155
<i-0c208bc6d31fa6bf1> EXEC echo ~
<i-0c208bc6d31fa6bf1> _wrap_command: 'echo QTPJHrIizAXitS...
我的 SSM 已针对其他功能正确设置。
我可以通过 ssm SSH 并通过 ssm 运行远程 playbook,只是不使用:
ansible_connection: aws_ssm
连接机制。
【问题讨论】:
标签: amazon-ec2 ansible aws-ssm