Ubuntu Ansible-Windows主机的预期模块

Ubuntu Ansible-Windows主机的预期模块,ubuntu,ansible,Ubuntu,Ansible,我正在使用ansible配置远程Windows主机。我试图通过ansible配置VSTS代理,在这个设置过程中,应该响应一些提示。我找到了一个名为“expect”的命令来执行它,下面给出了我的剧本 --- - hosts: windows tasks: - name: unarchive win_unzip: dest='C:\\agent1' src='C:\\devops\\agent.zip' - name: Configure Agnt

我正在使用ansible配置远程Windows主机。我试图通过ansible配置VSTS代理,在这个设置过程中,应该响应一些提示。我找到了一个名为“expect”的命令来执行它,下面给出了我的剧本

---
- hosts: windows
  tasks:
  - name: unarchive
    win_unzip:
      dest='C:\\agent1'
      src='C:\\devops\\agent.zip'
  - name: Configure Agnt
    expect:
       chdir: 'C:\\agent1'
       command: 'ConfigureAgent.cmd'
       echo: true
       responses:
         Accept the License: "Y"
         Enter the name for this agent (default is Agent-WindowsAgent): 'windowagent'
         Enter the URL for the Team Foundation Server: 'http://tfs.test.com:8080/tfs/testCollection$
         Configure this agent against which agent pool: 'testpool'
         Enter the path of the work folder for this agent: 'C:\\agent1\\_work'
 [WARNING]: No python interpreters found for host 52.230.224.117 (tried
 ['/usr/bin/python', 'python3.7', 'python3.6', 'python3.5', 'python2.7',
 'python2.6', '/usr/libexec/platform-python', '/usr/bin/python3', 'python'])

 fatal: [52.230.224.117]: FAILED! => {
"ansible_facts": {
    "discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"module_stderr": "Exception calling \"Create\" with \"1\" argument(s): \"At line:4 char:21\r\n+ def _ansiballz_main():\r\n+                     ~\r\nAn expression was expected after '('.\r\nAt line:13 char:27\r\n+     except (AttributeError, OSError):\r\n+                           ~\r\nMissing argument in parameter list.\r\nAt line:15 char:7\r\n+     if scriptdir is not None:\r\n+       ~\r\nMissing '(' after 'if' in if statement.\r\nAt line:22 char:7\r\n+     if sys.version_info < (3,):\r\n+       ~\r\nMissing '(' after 'if' in if statement.\r\nAt line:22 char:30\r\n+     if sys.version_info < (3,):\r\n+                              ~\r\nMissing expression after ','.\r\nAt line:22 char:25\r\n+     if sys.version_info < (3,):\r\n+                         ~\r\nThe '<' operator is reserved for future use.\r\nAt line:24 char:32\r\n+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)\r\n+                                ~\r\nMissing expression after ','.\r\nAt line:24 char:33\r\n+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)\r\n+                                 ~~~~~~~~~~~~~\r\nUnexpected token 'imp.PY_SOURCE' in expression or statement.\r\nAt line:24 char:32\r\n+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)\r\n+                                ~\r\nMissing closing ')' in expression.\r\nAt line:24 char:46\r\n+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)\r\n+                                              ~\r\nUnexpected token ')' in expression or statement.\r\nNot all parse errors were reported.  Correct the reported errors and try again.\"\r\nAt line:6 char:1\r\n+ $exec_wrapper = [ScriptBlock]::Create($split_parts[0])\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException\r\n    + FullyQualifiedErrorId : ParseException\r\n \r\nThe expression after '&' in a pipeline element produced an object that was not valid. It must result in a command \r\nname, a script block, or a CommandInfo object.\r\nAt line:7 char:2\r\n+ &$exec_wrapper\r\n+  ~~~~~~~~~~~~~\r\n    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException\r\n    + FullyQualifiedErrorId : BadExpression\r\n ",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
但我得到一个错误,如下所示

---
- hosts: windows
  tasks:
  - name: unarchive
    win_unzip:
      dest='C:\\agent1'
      src='C:\\devops\\agent.zip'
  - name: Configure Agnt
    expect:
       chdir: 'C:\\agent1'
       command: 'ConfigureAgent.cmd'
       echo: true
       responses:
         Accept the License: "Y"
         Enter the name for this agent (default is Agent-WindowsAgent): 'windowagent'
         Enter the URL for the Team Foundation Server: 'http://tfs.test.com:8080/tfs/testCollection$
         Configure this agent against which agent pool: 'testpool'
         Enter the path of the work folder for this agent: 'C:\\agent1\\_work'
 [WARNING]: No python interpreters found for host 52.230.224.117 (tried
 ['/usr/bin/python', 'python3.7', 'python3.6', 'python3.5', 'python2.7',
 'python2.6', '/usr/libexec/platform-python', '/usr/bin/python3', 'python'])

 fatal: [52.230.224.117]: FAILED! => {
"ansible_facts": {
    "discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"module_stderr": "Exception calling \"Create\" with \"1\" argument(s): \"At line:4 char:21\r\n+ def _ansiballz_main():\r\n+                     ~\r\nAn expression was expected after '('.\r\nAt line:13 char:27\r\n+     except (AttributeError, OSError):\r\n+                           ~\r\nMissing argument in parameter list.\r\nAt line:15 char:7\r\n+     if scriptdir is not None:\r\n+       ~\r\nMissing '(' after 'if' in if statement.\r\nAt line:22 char:7\r\n+     if sys.version_info < (3,):\r\n+       ~\r\nMissing '(' after 'if' in if statement.\r\nAt line:22 char:30\r\n+     if sys.version_info < (3,):\r\n+                              ~\r\nMissing expression after ','.\r\nAt line:22 char:25\r\n+     if sys.version_info < (3,):\r\n+                         ~\r\nThe '<' operator is reserved for future use.\r\nAt line:24 char:32\r\n+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)\r\n+                                ~\r\nMissing expression after ','.\r\nAt line:24 char:33\r\n+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)\r\n+                                 ~~~~~~~~~~~~~\r\nUnexpected token 'imp.PY_SOURCE' in expression or statement.\r\nAt line:24 char:32\r\n+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)\r\n+                                ~\r\nMissing closing ')' in expression.\r\nAt line:24 char:46\r\n+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)\r\n+                                              ~\r\nUnexpected token ')' in expression or statement.\r\nNot all parse errors were reported.  Correct the reported errors and try again.\"\r\nAt line:6 char:1\r\n+ $exec_wrapper = [ScriptBlock]::Create($split_parts[0])\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException\r\n    + FullyQualifiedErrorId : ParseException\r\n \r\nThe expression after '&' in a pipeline element produced an object that was not valid. It must result in a command \r\nname, a script block, or a CommandInfo object.\r\nAt line:7 char:2\r\n+ &$exec_wrapper\r\n+  ~~~~~~~~~~~~~\r\n    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException\r\n    + FullyQualifiedErrorId : BadExpression\r\n ",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
[警告]:找不到主机52.230.224.117的python解释器(已尝试)
['/usr/bin/python','python3.7','python3.6','python3.5','python2.7',',
‘python2.6’、‘usr/libexec/platformpython’、‘usr/bin/python3’、‘python’】
致命:[52.230.224.117]:失败!=>{
“可解释的事实”:{
“发现了解释器\u python”:“/usr/bin/python”
},
“更改”:错误,

“module\u stderr”:“异常调用\“Create\”并在第4行使用\“1\”参数\“21\r\n+def\u ansiballz\u main():\r\n+~\r\n在“(”之后应该有一个表达式。\r\n第13行字符:27\r\n+除了(AttributeError,OSError):\r\n+~\r\n参数列表中缺少参数。\r\n行:15个字符:7\r\n+如果scriptdir不是无:\r\n+~\r\n缺少“(”在if语句中的“if”之后。\r\n行:22个字符:7\r\n+如果sys.version\u info<(3,):\r\n+~\r\n缺少“(“if”语句中的“if”之后。\r\n行:22字符:30\r\n+if sys.version\u info<(3),:\r\n+~\r\n在“,”之后缺少表达式。\r\n行:22字符:25\r\n+if sys.version\u info<(3),:\r\n+~\r\n在Ansible Hosts文件中添加Windows Python环境变量

-->vi/etc/ansible/hosts(添加以下行)
[windows:vars]

ansible\u python\u解释器=c:\python\python

expect模块仅适用于基于linux的操作系统。