【问题标题】:Cant install package via ansible snap module无法通过 ansible snap 模块安装包
【发布时间】:2021-01-19 16:06:26
【问题描述】:

我只想通过 ansible 使用 molecule 完成一项简单的任务。以下代码如下:

- 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

【问题讨论】:

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


    【解决方案1】:

    我可以在 Ubuntu Ubuntu 20.04.1 LTS 上使用 snap 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
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        致将来遇到同样错误的人。似乎该错误与 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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-04-29
          • 2020-12-31
          • 1970-01-01
          • 2017-11-01
          • 2023-03-28
          • 2019-10-09
          • 2020-02-23
          • 1970-01-01
          相关资源
          最近更新 更多