无法通过 ansible snap 模块安装软件包

时间:2021-01-19 16:06:26

标签: python python-3.x linux ansible ansible-2.x

我只想使用分子通过ansible做一个简单的任务。以下代码如下:

- name: Continue to install applications
  snap:
    name: "{{ item }}"
    classic: true
  loop:
    - bitwarden
    - clion

但我收到以下错误。使用 --debug 选项我没有得到更多信息

Task exception was never retrieved
future: <Task finished name='Task-19' coro=<_read_stream() done, defined at /home/vlad/.local/lib/python3.8/site-packages/subprocess_tee/__init__.py:21> exception=ValueError('Separator is found, but chunk is longer than limit')>
Traceback (most recent call last):
  File "/usr/lib/python3.8/asyncio/streams.py", line 540, in readline
    line = await self.readuntil(sep)
  File "/usr/lib/python3.8/asyncio/streams.py", line 635, in readuntil
    raise exceptions.LimitOverrunError(
asyncio.exceptions.LimitOverrunError: Separator is found, but chunk is longer than limit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/vlad/.local/lib/python3.8/site-packages/subprocess_tee/__init__.py", line 23, in _read_stream
    line = await stream.readline()
  File "/usr/lib/python3.8/asyncio/streams.py", line 549, in readline
    raise ValueError(e.args[0])
ValueError: Separator is found, but chunk is longer than limit
CRITICAL Ansible return code was 2, command was: ansible-playbook --diff --inventory....

Ansible 版本:

ansible 2.10.4
  config file = None
  configured module search path = ['/home/vlad/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/vlad/.local/lib/python3.8/site-packages/ansible
  executable location = /home/vlad/.local/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]

分子版本:

molecule 3.2.2 using python 3.8 
    ansible:2.10.4
    delegated:3.2.2 from molecule
    vagrant:0.6.1 from molecule_vagrant

3 个答案:

答案 0 :(得分:0)

我可以在 Ubuntu snap 上使用 Ubuntu 20.04.1 LTS ansible 模块安装 snap 包

代码:

---

- name: Playbook for installing required packages
  hosts: localhost
  gather_facts: True
  connection: local
  become: yes
  become_user: root

  tasks:

  - name: Install required packages
    snap:
      classic: yes
      state: present
      name:
        - bitwarden
        - clion

答案 1 :(得分:0)

我检查了机器日志,当 ansible 尝试在我的情况下安装 snap 时,内存不足

答案 2 :(得分:0)

致以后遇到同样错误的人。该错误似乎与 snap 模块或任何其他模块无关。输出将打印在 stdout/stderr 上,新行 (\n) 将转义为 \\n。 流模块将尝试在内容中找到 b'\n' ,但由于换行符被转义,它将无法找到它。所以会引发错误。

如问题中所述,错误来源是 asyncio/streams.py 模块,而不是 ansible 本身。

解决此问题的一种方法是通过对任务使用 no_log: true 来限制 ansible 输出。

ansible 会打印合理的错误信息,而不是抛出 python 的错误。

- name: Check hbase regionserver jmx exporter
  hosts: hbase_regionservers
  tasks:
    - name: Check 'num regions' item
      uri:
        url: "http://{{ inventory_hostname }}:26010/metrics"
        return_content: true
      register: metrics
      no_log: true
      failed_when: metrics.content.find('hbase_regionserver_tables_num_tables 2.0') == -1