【发布时间】:2020-01-02 03:09:21
【问题描述】:
我在配置文件中有我的保险库令牌,并试图从我本地的保险库中读取用户名和密码,并将这些变量传递给远程主机。在下面尝试了这个,能够读取用户名和密码作为 getusername 和 getpassword 的一部分,但在最后一个块中,它们无法读取为变量,请让我知道我做错了什么。
- name: wait for native_transport_port
wait_for:
host="{{ inventory_hostname }}"
port="9042"
state=started
timeout=300
- name: getusername
gather_facts: no
become_user: pc_user
tasks:
shell: source ~/.profile ;vault_username=`vault read --field=adm path`
delegate_to: 127.0.0.1
- name: getpassword
gather_facts: no
become_user: pc_user
tasks:
shell: source ~/.profile ;vault_p=`vault read --field=adm_p path`
delegate_to: 127.0.0.1
- name: create keyspace
command: cqlsh -u $vault_username -p $vault_p -f filname"
become_user: ec2-user
【问题讨论】:
-
“块”
getusername和getpassword似乎是游戏,而不仅仅是任务 - 像wait for native_transport_port和create keyspace一样是另一个游戏的一部分。这是故意的,还是错误的?您提供的这个 sn-p 不是您正在运行的代码。如果您添加了用于发现问题的实际代码,将会有所帮助。 -
这是故意的。我主要关心的是我能够在 gettusername 和 getpassword vault_username 和 vault_p 中获得的值。在使用 $vault_username 和 $vault_p 时,我无法在创建密钥空间中传递它们。在键空间中传递这些变量值的方法是什么
-
我收到错误 [Bad credentials] message=\"提供的用户名 $vault_username 和/或密码不正确\"',)})"], "stdout": "", "stdout_lines" : []}
-
您需要将shell任务更改为“在其输出中回显字符串,并使用
register子句将其保存到ansible中的变量中。我将举一个例子作为答案。