【问题标题】:Ansible shell module variable (Tcl's quoting mechanism:)Ansible shell 模块变量(Tcl 的引用机制:)
【发布时间】: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[

【问题讨论】:

    标签: ansible tcl


    【解决方案1】:

    试试这个:

    - 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
    

    【讨论】:

    • 这是多么复杂的引用组合!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-15
    • 2022-11-07
    • 1970-01-01
    相关资源
    最近更新 更多