Ansible 查找插件 "password" 不在文件中保存密码

Ansible lookup plugin "password" does not save password in a file

有人可以帮忙吗? 我尝试实现 Ansible 密码生成器 enter link description here。问题是在(看似)成功运行后,我看不到密码文件 stored/created 在哪里? 但是当我删除 'credentials/' + item.0.client_username + 部分时,我可以看到创建的文件(我的 ansible 代码所在的位置)。 link中的文档并没有多说。 最下面也是默认文件的内容。

  - name: Add Client
    solace_client_username:
      name: "{{ item.0.client_username }}"
      msg_vpn: "{{ msg_vpn }}"
      settings:
        clientProfileName: "{{ item.1.clientProfileName }}"
        aclProfileName: "{{ item.1.aclProfileName }}"
        password: "{{ lookup('password',  'credentials/' + item.0.client_username + 'password.dat length=15 chars=ascii_letters,ascii_uppercase,ascii_lowercase,digits') }}"
    with_subelements:
    - "{{ clients }}"
    - specs 

默认 yml:

clients:
  - client_username: export-john-doe
    specs: 
      - aclProfileName: export-john-doe-profile
        clientProfileName: default
        enabled: true

  - client_username: staging-john-doe
    specs: 
      - aclProfileName: staging-john-doe-profile
        clientProfileName: default
        enabled: true

问:"密码文件存储在哪里?"

答:在controller/master。 lookup plugins 运行 总是在 master 上。

" ... lookups execute and are evaluated on the Ansible control machine."

"Lookups are executed with a working directory relative to the role or play, as opposed to local tasks, which are executed relative the executed script."


您的代码应该可以正常工作。例如

- debug:
    msg: "{{ lookup('password',
             'credentials/' + item.0.client_username + 'password.dat
             length=15
             chars=ascii_letters,ascii_uppercase,ascii_lowercase,digits') }}"
  with_subelements:
    - "{{ clients }}"
    - specs

在当前目录的控制器上给出

shell> tree credentials/
credentials/
├── export-john-doepassword.dat
└── staging-john-doepassword.dat

0 directories, 2 files

shell> cat credentials/export-john-doepassword.dat
bcpJprWLv3srojj

shell> cat credentials/staging-john-doepassword.dat
rnyTJ3qpZczY0Qc

以上 Vladimir Botka 的回答是正确的。我刚刚注意到这会创建另一个名为“credentials”的文件夹,其中包含每个密码的文件。该文件夹位于根目录下(您 运行 来自的 ansible 代码)。