Ansible pip module: name package and umask 0022 Fatal error: invalid literal for int() with base 8: '18' umask must be an octal integer

Ansible pip module: name package and umask 0022 Fatal error: invalid literal for int() with base 8: '18' umask must be an octal integer

ansible/ansible-playbook版本:2.1.2.0

我的剧本中有以下操作:

- name: Install cli (as well)
  pip:
    name: "{{ mycompany_pip_pkg }}"
    umask: 0022

即使我遵循了 Ansible pip 模块的文档,为什么我会收到以下致命错误消息:http://docs.ansible.com/ansible/pip_module.html

错误:

TASK [company.company-ansible : Install cli (as well)] ****************
fatal: [localhost]: FAILED! => {"changed": false, "details": "invalid literal for int() with base 8: '18'", "failed": true, "msg": "umask must be an octal integer"}

Ansible pip 文档说:

The system umask to apply before installing the pip package. This is useful, for example, when installing on systems that have a very restrictive umask by default (e.g., 0077) and you want to pip install packages which are to be used by all users. Note that this requires you to specify desired umask mode in octal, with a leading 0 (e.g., 0077).

http://programtalk.com/vs2/python/749/ansible-modules-core/packaging/language/pip.py/ 显示以下代码:

if umask and not isinstance(umask, int):
    try:
        umask = int(umask, 8)
    except Exception:
        module.fail_json(msg="umask must be an octal integer",
                         details=to_native(sys.exc_info()[1]))

PS: 以下语法有效!但为什么上面那个不起作用?

- name: Install cli (as well)
  pip: name="{{ mycompany_pip_pkg }}" umask=0022

更新:
问题:
1) 为什么在 Ansible pip 模块中,当 name 属性 的值包含无效的包名称时,此模块对于 umask 属性 失败值(在我的情况下是正确的)?

Ansible 需要 key=value 格式的模块参数,即使自由格式(YAML 样式)参数仍然被接受但不推荐。

来自Conventions/Recommendations

Modules can also take free-form arguments instead of key-value or json but this is not recommended.

用引号括起 umask 对我有用。 点: 名称:uwsgi 状态:现在 掩码:'0022'

# ls -lah /bin/uwsgi -rwxr-xr-x. 1 root root 1.3M Jan 21 12:12 /bin/uwsgi

只需将 umask 值括在引号中。

无效:

  pip:
    name:
      - pika
      - argparse
    umask: 0022

有效:

  pip:
    name:
      - pika
      - argparse
    umask: "0022"

"file" 模块曾经出现过同样的问题,直到它被 https://github.com/ansible/ansible/issues/9196 修复。正如其他人指出的那样,使用 key=value 语法也可以。