Ansible 2.8.7 API 使用异常1:"connection plugin class ansible.utils.sentinel.Sentinel was not found"

    系统环境
    ------
     - CENTOS7.6-1810
     - virtualenv
     - python 3.8.0
     - ansible 2.8.7
     - eclipse 201909 + PyDEV 7.4


    以前自定义options:
    
    from collections import namedtuple
    from optparse import Values
    
        options = {'verbosity': 0, 'connection': 'smart', 'timeout': 15,..........}
        ops = Values(options)
    
    
    现在改为如下, 异常消失:
    
    from ansible import context
    from ansible.module_utils.common.collections import ImmutableDict

     方法1.
    context._init_global_context(ops)

    方法2.
        context.CLIARGS = ImmutableDict(
            connection='smart', module_path=None, verbosity=5,
            forks=10, become=None, become_method=None, 
            become_user=None, check=False, diff=False)

    #如果报键值异常:

    Traceback (most recent call last):
        if context.CLIARGS['syntax']:
      File "/mydev/.envs/ansible287/lib/python3.8/site-packages/ansible/module_utils/common/collections.py", line 20, in __getitem__
        return self._store[key]
      KeyError: 'syntax'

则追加相应Options参数,如syntax=None,start_at_task=None。。。。。。

你可能感兴趣的:(Ansible2.8.7)