当前位置: 首页>>代码示例>>Python>>正文


Python PlayContext.set_task_and_variable_override方法代码示例

本文整理汇总了Python中ansible.playbook.play_context.PlayContext.set_task_and_variable_override方法的典型用法代码示例。如果您正苦于以下问题:Python PlayContext.set_task_and_variable_override方法的具体用法?Python PlayContext.set_task_and_variable_override怎么用?Python PlayContext.set_task_and_variable_override使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ansible.playbook.play_context.PlayContext的用法示例。


在下文中一共展示了PlayContext.set_task_and_variable_override方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_play_context

# 需要导入模块: from ansible.playbook.play_context import PlayContext [as 别名]
# 或者: from ansible.playbook.play_context.PlayContext import set_task_and_variable_override [as 别名]
    def test_play_context(self):
        (options, args) = self._parser.parse_args(['-vv', '--check'])
        play_context = PlayContext(options=options)
        self.assertEqual(play_context.connection, 'smart')
        self.assertEqual(play_context.remote_addr, None)
        self.assertEqual(play_context.remote_user, pwd.getpwuid(os.geteuid())[0])
        self.assertEqual(play_context.password, '')
        self.assertEqual(play_context.port, None)
        self.assertEqual(play_context.private_key_file, C.DEFAULT_PRIVATE_KEY_FILE)
        self.assertEqual(play_context.timeout, C.DEFAULT_TIMEOUT)
        self.assertEqual(play_context.shell, None)
        self.assertEqual(play_context.verbosity, 2)
        self.assertEqual(play_context.check_mode, True)
        self.assertEqual(play_context.no_log, None)

        mock_play = MagicMock()
        mock_play.connection    = 'mock'
        mock_play.remote_user   = 'mock'
        mock_play.port          = 1234
        mock_play.become        = True
        mock_play.become_method = 'mock'
        mock_play.become_user   = 'mockroot'
        mock_play.no_log        = True

        play_context = PlayContext(play=mock_play, options=options)
        self.assertEqual(play_context.connection, 'mock')
        self.assertEqual(play_context.remote_user, 'mock')
        self.assertEqual(play_context.password, '')
        self.assertEqual(play_context.port, 1234)
        self.assertEqual(play_context.no_log, True)
        self.assertEqual(play_context.become, True)
        self.assertEqual(play_context.become_method, "mock")
        self.assertEqual(play_context.become_user, "mockroot")

        mock_task = MagicMock()
        mock_task.connection    = 'mocktask'
        mock_task.remote_user   = 'mocktask'
        mock_task.become        = True
        mock_task.become_method = 'mocktask'
        mock_task.become_user   = 'mocktaskroot'
        mock_task.become_pass   = 'mocktaskpass'
        mock_task.no_log        = False

        all_vars = dict(
            ansible_connection = 'mock_inventory',
            ansible_ssh_port = 4321,
        )

        play_context = PlayContext(play=mock_play, options=options)
        play_context = play_context.set_task_and_variable_override(task=mock_task, variables=all_vars)
        self.assertEqual(play_context.connection, 'mock_inventory')
        self.assertEqual(play_context.remote_user, 'mocktask')
        self.assertEqual(play_context.port, 4321)
        self.assertEqual(play_context.no_log, False)
        self.assertEqual(play_context.become, True)
        self.assertEqual(play_context.become_method, "mocktask")
        self.assertEqual(play_context.become_user, "mocktaskroot")
        self.assertEqual(play_context.become_pass, "mocktaskpass")
开发者ID:thebeefcake,项目名称:masterless,代码行数:60,代码来源:test_play_context.py

示例2: test_play_context

# 需要导入模块: from ansible.playbook.play_context import PlayContext [as 别名]
# 或者: from ansible.playbook.play_context.PlayContext import set_task_and_variable_override [as 别名]
def test_play_context(mocker, parser):
    (options, args) = parser.parse_args(['-vv', '--check'])
    play_context = PlayContext(options=options)

    assert play_context._attributes['connection'] == C.DEFAULT_TRANSPORT
    assert play_context.remote_addr is None
    assert play_context.remote_user is None
    assert play_context.password == ''
    assert play_context.port is None
    assert play_context.private_key_file == C.DEFAULT_PRIVATE_KEY_FILE
    assert play_context.timeout == C.DEFAULT_TIMEOUT
    assert play_context.shell is None
    assert play_context.verbosity == 2
    assert play_context.check_mode is True
    assert play_context.no_log is None

    mock_play = mocker.MagicMock()
    mock_play.connection = 'mock'
    mock_play.remote_user = 'mock'
    mock_play.port = 1234
    mock_play.become = True
    mock_play.become_method = 'mock'
    mock_play.become_user = 'mockroot'
    mock_play.no_log = True

    play_context = PlayContext(play=mock_play, options=options)
    assert play_context.connection == 'mock'
    assert play_context.remote_user == 'mock'
    assert play_context.password == ''
    assert play_context.port == 1234
    assert play_context.become is True
    assert play_context.become_method == "mock"
    assert play_context.become_user == "mockroot"

    mock_task = mocker.MagicMock()
    mock_task.connection = 'mocktask'
    mock_task.remote_user = 'mocktask'
    mock_task.no_log = mock_play.no_log
    mock_task.become = True
    mock_task.become_method = 'mocktask'
    mock_task.become_user = 'mocktaskroot'
    mock_task.become_pass = 'mocktaskpass'
    mock_task._local_action = False
    mock_task.delegate_to = None

    all_vars = dict(
        ansible_connection='mock_inventory',
        ansible_ssh_port=4321,
    )

    mock_templar = mocker.MagicMock()

    play_context = PlayContext(play=mock_play, options=options)
    play_context = play_context.set_task_and_variable_override(task=mock_task, variables=all_vars, templar=mock_templar)

    assert play_context.connection == 'mock_inventory'
    assert play_context.remote_user == 'mocktask'
    assert play_context.port == 4321
    assert play_context.no_log is True
    assert play_context.become is True
    assert play_context.become_method == "mocktask"
    assert play_context.become_user == "mocktaskroot"
    assert play_context.become_pass == "mocktaskpass"

    mock_task.no_log = False
    play_context = play_context.set_task_and_variable_override(task=mock_task, variables=all_vars, templar=mock_templar)
    assert play_context.no_log is False
开发者ID:ernstp,项目名称:ansible,代码行数:69,代码来源:test_play_context.py


注:本文中的ansible.playbook.play_context.PlayContext.set_task_and_variable_override方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。