【发布时间】:2021-02-26 17:39:34
【问题描述】:
我正在尝试使用带有 send 的 ansible shell 模块来执行 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[。
【问题讨论】: