gpt4 book ai didi

python - 即使安装了 passlib,Ansible password_hash 也不会使用 bcrypt

转载 作者:行者123 更新时间:2023-12-05 08:26:14 25 4
gpt4 key购买 nike

我正在尝试调用 Ansible 的 password_hash 函数...

{{ admin_password | password_hash('bcrypt') }}

我已经尝试了十几种方法来告诉 Ansible passlib 和 python 2.7 在哪里,但无论如何,我不断得到结果......

"AnsibleFilterError: crypt.crypt does not support 'bcrypt' algorithm"

据我所知,ansible 过去只使用 crypt,但较新的版本(我目前使用的是 2.7.9)使用 passlib 和 passlib据我所知支持 bcrypt(这是有限的)。我已将以下内容添加到我的主机文件中...

ansible_python_interpreter = /usr/bin/python2.7

我正在像这样安装 PIP 和 Passlib...

- name: Install PY stuff...
yum:
name: ['python2-pip','python2-passlib']
state: present

- name: Ensure bcrypt support is installed for python passlib
pip:
name: "passlib[bcrypt]"
executable: pip-2.7

我本以为 yum 调用可以正确设置 passlib 但它没有用在职的。我不确定通过 yum 安装时 passlib 是否包含 bcrypt,因为它似乎只使用 PIP 时不包含,所以为了以防万一,我都做了。没有快乐。

我应该补充一点,我在 Amazon Linux 2 上的 AWS 中,并且我已经启用了 epel 存储库等。


编辑:我已经尝试了评论中的一些建议(使用 passlib 1.6,验证 bcrypt 是否适用于 python),虽然我可以验证 passlib 在 python 中测试时是否有效,但我继续从中得到相同的答案Ansible AnsibleFilterError: crypt.crypt 不支持 'bcrypt' 算法

我发现的唯一与此相关的是:https://github.com/ansible/ansible/issues/17266但它描述了默认情况下寻找 passlib 并且仅在 crypt.crypt 不存在时回退。那么,为什么 python 在我手动运行时看到 passlib,而不是从 playbook 中看到?

最佳答案

首先,确认 Ansible 正在使用您认为的 Python。查看 head -1 $(which ansible),您应该会看到如下内容:

#!/usr/bin/python2

确保您已经在 Python 可以找到的地方安装了 passlib:

$ /usr/bin/python2
Python 2.7.15 (default, Oct 15 2018, 15:24:06)
[GCC 8.1.1 20180712 (Red Hat 8.1.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import passlib
>>>

我使用的是 Fedora 28,所以我可以简单地 yum -y install
python2-passlib
.

确保passlib支持bcrypt:

>>> from passlib.hash import bcrypt
>>> bcrypt.hash('secret')
'$2b$12$3YUj4BgoJ8ba1H4XtH/p3.4DG0lMgaHQ4qYshpj/.COe1eHEU.71K'
>>>

如果以上都成功,password_hash 过滤器应该工作:

$ cat playbook.yml
---
- hosts: localhost
gather_facts: false
tasks:
- debug:
msg: "{{ 'secret' | password_hash('bcrypt') }}"

$ ansible-playbook playbook.yml
PLAY [localhost] ********************************************************************

TASK [debug] ************************************************************************
ok: [localhost] => {
"msg": "$2b$12$H9rnvJwYtSoy05WHMYuJR.Kaz9kxLJleT7XUsIauWwd3Mdk0H/Kl6"
}

PLAY RECAP **************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0

关于python - 即使安装了 passlib,Ansible password_hash 也不会使用 bcrypt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55875213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com