docker - 如何从 Ansible 运行 shell 别名 docker 命令?
问题描述
一位客户有一个运行本地操作的剧本,在这种情况下,是针对 RDS 端点的 sqlplus 命令。
shell: "echo exit|sqlplus64 '{{db_pnyx_username}}/{{db_pnyx_password}}@//{{ host }}:{{ port }}/{{db_pnyx_service_name}}' @vhosts.sql"
当我运行 Ubuntu 时,我很好奇如何避免由于 sqlplus 包而安装如此多的包依赖项,所以我决定尝试以容器方式。
- name : Execute SQL
shell: "echo exit|docker run --rm --net=host -v $PWD:/tmp rubendob/sqlplus:dockerplus '{{db_pnyx_username}}/{{db_pnyx_password}}@//{{ host }}:{{ port }}/{{db_pnyx_service_name}}' @/tmp/vhosts.sql"
register: result
它奏效了!
但我还想使用我的 .profile 文件中的别名快捷方式运行 docker,如下所示:
alias sqlplus64='docker run --rm --net=host -v $PWD:/tmp rubendob/sqlplus:dockerplus'
Ansible 总是返回错误:
"stderr": "/bin/sh: 1: sqlplus64: not found", "stderr_lines": ["/bin/sh: 1: sqlplus64: not found"], "stdout": "", "stdout_lines": []}
有没有办法根据最佳实践实现这一目标?我敢打赌我在这里做了很多坏事:(
解决方案
推荐阅读
- java - Is there an example for Implicit Vs Explicit threading in java?
- java - Jetty 11 Doesn't Detect Servlets
- cookies - Unable to set cookie on Safari (Works on Chrome)
- python - How to fix setup.py file at py2app
- sql - One column into multiple columns by type, plus concatenating multiples
- flask - Flask not displaying debug mode
- javascript - Printing to the screen using innerHTML and innerText not working with my htmlCollection
- javascript - Why is the semi-colon required after the string `toInsert` for the `forEach` to work in JavaScript? Undefined error
- configuration - Termux 上 ArchLinux 的 MPI 可执行文件失败
- php - 如何在 WordPress 和 Timber 中输出附加到类别的 ACF 元字段