Ansible 不会从 shell 模块注册变量
Posted
技术标签:
【中文标题】Ansible 不会从 shell 模块注册变量【英文标题】:Ansible won't register variable from shell module 【发布时间】:2019-02-05 10:34:40 【问题描述】:我在其他游戏中使用register
,它工作正常。主要问题似乎是在将它与 shell
模块一起使用时。
这是我目前的剧本
- name: Execute create-auth-key.sql
shell: echo exit | sqlplus -l data_security_schema_username / data_security_schema_password @\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=TCP\)\(HOST= data_security_schema_hostname \)\(PORT= data_security_schema_port \)\)\(CONNECT_DATA=\(SERVER=dedicated\)\(SERVICE_NAME= data_security_schema_service_name \)\)\) @/tmp/create-auth-key.sql;
register: sqlplus-stdout
- name: Set Fact aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
set_fact:
checking: " sqlplus-stdout.stdout "
- name: print aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
debug:
msg: " checking "
sqlplus 正在正确运行事务,但是我想过滤事务的输出以获取生成的身份验证密钥。为此,我需要在 var 中输出 sqlplus。这是抛出的错误。
FAILED! => "msg": "The task includes an option with an undefined variable. The error was: 'sqlplus' is undefined\n\nThe error appears to have been in '/var/lib/jenkins/.ansible/roles/test.auth-transaction/tasks/create-auth-key-and-obc.yml
为什么我的set fact
无法识别sqlplus-stdout
?
【问题讨论】:
【参考方案1】:你不能在 python vars 中使用-
..
- name: Execute create-auth-key.sql
shell: echo exit | sqlplus -l data_security_schema_username / data_security_schema_password @\(DESCRIPTION=\(ADDRESS=\(PROTOCOL=TCP\)\(HOST= data_security_schema_hostname \)\(PORT= data_security_schema_port \)\)\(CONNECT_DATA=\(SERVER=dedicated\)\(SERVICE_NAME= data_security_schema_service_name \)\)\) @/tmp/create-auth-key.sql;
register: sqlplusstdout
- name: Set Fact aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
set_fact:
checking: " sqlplusstdout.stdout "
- name: print aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
debug:
msg: " checking "
【讨论】:
以上是关于Ansible 不会从 shell 模块注册变量的主要内容,如果未能解决你的问题,请参考以下文章