docker - ansible aws ecr 登录而不使用 docker 命令
问题描述
我想使用 ansible 登录 aws docker ecr 注册表
# return docker login -u AWS -p <token>
-name: dget docker command
shell: "aws ecr get-login --region {{ aws_region }}"
register: docker_login_command
-name: docker login
shell: "{{docker_login_command.output}}"
这将需要在我们的机器上安装 docker cli。但我们正在使用 docker 容器通过共享 docker 套接字运行 ansible。有没有办法不为此使用docker cli?
解决方案
尝试这个。这对我有用。
- name: ecr docker get-authorization-token
shell: "aws ecr get-authorization-token \
--profile {{ envsettings.infra.aws_profile }} --region {{ envsettings.infra.aws_region }}"
register: ecr_command
- set_fact:
ecr_authorization_data: "{{ (ecr_command.stdout | from_json).authorizationData[0] }}"
- set_fact:
ecr_credentials: "{{ (ecr_authorization_data.authorizationToken | b64decode).split(':') }}"
- name: docker_repository - Log into ECR registry and force re-authorization
docker_login:
registry_url: "{{ ecr_authorization_data.proxyEndpoint.rpartition('//')[2] }}"
username: "{{ ecr_credentials[0] }}"
password: "{{ ecr_credentials[1] }}"
reauthorize: yes
它需要 docker pip python 模块。在上述代码之前安装
- name: install required packages for this role
pip:
state: present
name: docker
executable: /usr/bin/pip3
推荐阅读
- flutter - 推后如何在脚手架树中弹出抽屉
- cakephp - CakePHP 教程错误:对 /users 的请求没有应用任何授权检查
- html - Vuetify DataTable - 垂直对齐单元格内容
- python - Python Azure 事件中心使用事件属性
- css - 符合内容大小的网格框
- c# - 在 System.Windows.Data.ListCollectionView 中导航项目时,CurrentPosition 和当前索引不同步
- function - 尝试在 Kotlin 类中使用 if 函数
- python - Python - 通过键数组更改嵌套值
- c - 在 C 中声明结构后的变量是什么意思?
- c++ - 致命错误:模板实例化深度超过最大值 900