如何在Ansible中使用命令stdin? [英] How to use command stdin in Ansible?
问题描述
我已经尝试过此:
- name: Log into Docker registry
command: docker login --username "{{ docker_registry_username }}" --password-stdin
stdin: "{{ docker_registry_password }}"
这将导致警告和失败的命令:
This results in a warning and a failing command:
[警告]:忽略无效的属性:stdin
[WARNING]: Ignoring invalid attribute: stdin
...
无法从非TTY设备执行交互式登录
Cannot perform an interactive login from a non TTY device
我也尝试过此:
- name: Log into Docker registry
command: docker login --username "{{ docker_registry_username }}" --password-stdin
stdin: "{{ docker_registry_password }}"
这会导致语法错误:
错误!加载YAML时出现语法错误.
ERROR! Syntax Error while loading YAML.
command
stdin
是否在Ansible 2.7中实际工作?如果是这样,我应该如何使用它?
Does command
stdin
actually work in Ansible 2.7? If so, how am I supposed to use it?
推荐答案
If you want to use the stdin
argument to the command
module, take a look at the docs, which show examples using other options such as creates
, which looks like this:
# You can also use the 'args' form to provide the options.
- name: This command will change the working directory to somedir/ and will only run when /path/to/database doesn't exist.
command: /usr/bin/make_database.sh arg1 arg2
args:
chdir: somedir/
creates: /path/to/database
对于您的用例,您需要:
For your use case, you would want:
- name: Log into Docker registry
command: docker login --username "{{ docker_registry_username }}" --password-stdin
args:
stdin: "{{ docker_registry_password }}"
您的第一次尝试失败,因为您实际上希望将stdin
设置为任务级别的键(例如when
或ignore_errors
等),而您却想将它作为command
模块的参数.
Your first attempt failed because you were setting stdin
as a key at the task level (like when
or ignore_errors
, etc), when you actually want it to be an argument to the command
module.
您的第二次尝试失败,因为它不是有效的YAML.
Your second attempt failed because it wasn't valid YAML.
这篇关于如何在Ansible中使用命令stdin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!