Ansible shell 模块变量(Tcl 的引用机制:)
Ansible shell module variable (Tcl's quoting mechanism:)
我正在尝试将 ansible shell 模块与 send
一起使用来执行 python 脚本。
- name: encrypt password
shell: |
spawn python3 "/usr/local/bin/encryptor.py"
expect -re "Enter data for encryption:"
send {"{{ secret }}"}
send "\n"
expect eof
args:
executable: /usr/bin/expect
问题是要加密的密码中有一个 [
,因此,根据此处 Ansible: expect -> invalid command name 的答案,我必须按照上面的代码将密码包装在 {} 中。
但是,当我记录输入到工具中的内容时,我看到它正在加密 \"password[\"
,而变量 secret
只是 password[
。为什么要添加转义引号以及如何删除它们以便它只加密 passowrd[
.
试试这个:
- name: encrypt password
shell: |
spawn python3 "/usr/local/bin/encryptor.py"
expect -re "Enter data for encryption:"
send {{ "{" ~ secret ~ "}" }}
send "\n"
expect eof
args:
executable: /usr/bin/expect
我正在尝试将 ansible shell 模块与 send
一起使用来执行 python 脚本。
- name: encrypt password
shell: |
spawn python3 "/usr/local/bin/encryptor.py"
expect -re "Enter data for encryption:"
send {"{{ secret }}"}
send "\n"
expect eof
args:
executable: /usr/bin/expect
问题是要加密的密码中有一个 [
,因此,根据此处 Ansible: expect -> invalid command name 的答案,我必须按照上面的代码将密码包装在 {} 中。
但是,当我记录输入到工具中的内容时,我看到它正在加密 \"password[\"
,而变量 secret
只是 password[
。为什么要添加转义引号以及如何删除它们以便它只加密 passowrd[
.
试试这个:
- name: encrypt password
shell: |
spawn python3 "/usr/local/bin/encryptor.py"
expect -re "Enter data for encryption:"
send {{ "{" ~ secret ~ "}" }}
send "\n"
expect eof
args:
executable: /usr/bin/expect