【问题标题】:Ansible "ERROR! Attempting to decrypt but no vault secrets found" but I'm not decrypting anythingAnsible“错误!尝试解密但未找到保险库机密”但我没有解密任何内容
【发布时间】:2020-10-08 11:48:52
【问题描述】:

奇怪而令人沮丧的错误

我正在尝试为 Ansible 学习和创建一个 python 模块。 我正在关注此页面:Medium.com 这是一个本地模块,所以我只想使用./library/module.py

代码:

剧本

---
- hosts: localhost    # I've used 127.0.0.1 here also
  connection: local

  vars:
    - Test: "This is a test"

  tasks:
  - name: set result
    set_fact:
      result: "set"

  - name: Test that my hello_world module works
    hello_world:
    register: result

  - debug: var=result
...

该模块是一个用于打印“Hello World”的简单 Python 脚本。 是./library/hello_world.py

模块

#!/usr/bin/python

from ansible.module_utils.basic import *

def main():
    module = AnsibleModule(argument_spec={})
    theReturnValue = {"hello": "world"}
    module.exit_json(changed=False, meta=theReturnValue)

if __name__ == '__main__':
    main()

我的 ansible.config

[defaults]
inventory = ./inventory
roles_path = ./roles
library = ./library
filter_plugins = ./plugins/filter
lookup_plugins = ./plugins/lookup
callback_whitelist = profile_tasks,timer
log_path = ./ansible.log
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /tmp/server_configurations/Facts/
fact_caching_timeout = 86400
host_key_checking = True
timeout=60

[inventory]
enable_plugins = host_list, ini, script, yaml, auto

[ssh_connection]
pipelining=True
control_path = %(directory)s/ssh-%%h-%%p-%%r

我的问题

当我没有调用解锁任何东西时,为什么我的 playbook 出现 Vault 错误? 我从头开始创建了另一个剧本,看看是否有任何复制错误。没有,并且得到了同样的错误。

错误

ansible@VirtualBox:/media/ubuntu20$ ansible-playbook module_test.yml --connection="local 127.0.0.1" -vv
ansible-playbook 2.9.6
  config file = /media/ubuntu20/ansible.cfg
  configured module search path = ['/media/ubuntu20/library']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.8.2 (default, Jul 16 2020, 14:00:26) [GCC 9.3.0]
Using /media/ubuntu20/ansible.cfg as config file

PLAYBOOK: module_test.yml **********************************************************************************************************************************************************
1 plays in module_test.yml
PLAY [localhost] *******************************************************************************************************************************************************************
ERROR! Attempting to decrypt but no vault secrets found

这个错误令人困惑,因为我没有调用任何保管库,也没有使用任何库存。 我手动键入剧本,以防我复制了我不想要的任何内容。
我使用了各种“本地”设置来强制本地化并且没有错误更改。 即使在-vvvv 我只是同样的错误行也无济于事。

如果这是一个模块错误,那为什么要显示一个 Vault 错误?

(我的 ./inventory/group_vars 中确实有保管库,但我不使用它们) 我对此感到头疼。

【问题讨论】:

  • I do have vaults in my ./inventory/group_vars, but I don't use them 如果你有它们,无论你以后是否真正使用它们,ansible 都会加载它们。
  • 现在,如何阻止它这样做。
  • I don't use any inventory => 这不是你的 ansible.cfg 所说的。无论如何,ansible 至少会尝试加载默认库存。如何停止:提供 vault_password 或更改不需要的库存。
  • 好的,成功了:ansible-playbook module_test.yml --connection="local 127.0.0.1" --vault-pass "/home/ansible/.ssh/ansible_vault_key" -vv

标签: python ansible


【解决方案1】:

好的,问题是我库存中的保险库。 即使我没有直接请求这些保险库,Ansible 也会访问这些保险库。

所以当我添加 --vault-pass "<key path" 时,剧本就跑了。

ansible-playbook module_test.yml --connection="local 127.0.0.1" --vault-pass "/home/ansible/.ssh/ansible_vault_key" -vv

剧本输出的最后一部分

task path: /media/ubuntu20/module_test.yml:15
Thursday 08 October 2020  14:20:22 +0200 (0:00:00.142)       0:00:03.013 ****** 
ok: [localhost] => {"changed": false, "meta": {"hello": "world"}}

TASK [debug] ***********************************************************************************************************************************************************************
task path: /media/ubuntu20/module_test.yml:19
Thursday 08 October 2020  14:20:23 +0200 (0:00:00.966)       0:00:03.979 ****** 
ok: [localhost] => {
    "result": {
        "changed": false,
        "failed": false,
        "meta": {
            "hello": "world"
        }
    }
}
META: ran handlers
META: ran handlers

PLAY RECAP *************************************************************************************************************************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

【讨论】:

  • 在较新版本的 ansible 中是 --vault-password-file="/some/directory/ansible.cfg"
【解决方案2】:

以防万一这对任何人都有用,对我来说问题是我之前使用sudo apt update && sudo apt upgrade升级了操作系统。

Ansible 已更新,之前的配置文件 /etc/ansible/ansible.cfg 已移至 /etc/ansible/ansible.cfg.dpkg-old。我的保管库通行证路径在文件中写为:

vault_password_file = /home/user/Documents/.vault_pass.txt

我把ansible.cfg.dpkg-old的内容复制到ansible.cfg,又找到了vault-pass文件,不用自己输入pass。

不管怎样,解决这个问题的方法也是使用ansible.cfg文件中的vault_password_file变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    相关资源
    最近更新 更多