使用AWS交互的Ansible会引发异常

问题描述 投票:0回答:1

我试图运行一个剧本来自动化AWS,但我遇到了这个我无法理解的异常。我有以下剧本:

- name: Just for testing
  hosts: windows-server
  gather_facts: no
  vars:
    aws_a_key: accesskey
    aws_s_key: secretkey
  tasks:
    - name: Ping
      win_ping:
    - name: Create a file to C:\Temp\test.conf
      win_file:
        path: C:\Temp\test.conf
        state: touch
    - name: Create another file to C:\Temp\test2.conf
      win_file:
        path: C:\Temp\test2.conf
        state: touch
    - name: Gather S3 facts
      aws_s3_bucket_facts:
        aws_access_key: "{{ aws_a_key }}"
        aws_secret_key: "{{ aws_s_key }}"
        region: eu-central-1

当我尝试执行它时,我收到以下错误:

PLAY [Just for testing] *******************************************************************************************************

TASK [Ping] *******************************************************************************************************************
ok: [WIN-40NQ43PHHA5]

TASK [Create a file to C:\Temp\test.conf] *************************************************************************************
changed: [WIN-40NQ43PHHA5]

TASK [Create another file to C:\Temp\test2.conf] ******************************************************************************
changed: [WIN-40NQ43PHHA5]

TASK [Gather S3 facts] ********************************************************************************************************
fatal: [WIN-40NQ43PHHA5]: FAILED! => {"changed": false, "module_stderr": "Exception calling \"Create\" with \"1\" argument(s): \"At line:4 char:21
+ def _ansiballz_main():
+                     ~
An expression was expected after '('.
At line:12 char:27
+     except (AttributeError, OSError):
+                           ~
Missing argument in parameter list.
At line:14 char:7
+     if scriptdir is not None:
+       ~
Missing '(' after 'if' in if statement.
At line:21 char:7
+     if sys.version_info < (3,):
+       ~
Missing '(' after 'if' in if statement.
At line:21 char:30
+     if sys.version_info < (3,):
+                              ~
Missing expression after ','.
At line:21 char:25
+     if sys.version_info < (3,):
+                         ~
The '<' operator is reserved for future use.
At line:23 char:32
+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)
+                                ~
Missing expression after ','.
At line:23 char:33
+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)
+                                 ~~~~~~~~~~~~~
Unexpected token 'imp.PY_SOURCE' in expression or statement.
At line:23 char:32
+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)
+                                ~
Missing closing ')' in expression.
At line:23 char:46
+         MOD_DESC = ('.py', 'U', imp.PY_SOURCE)
+                                              ~
Unexpected token ')' in expression or statement.
Not all parse errors were reported.  Correct the reported errors and try again.
\"
At line:6 char:1
+ $exec_wrapper = [ScriptBlock]::Create($split_parts[0])
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ParseException

The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command 
name, a script block, or a CommandInfo object.
At line:7 char:2
+ &$exec_wrapper
+  ~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : BadExpression
 ", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
    to retry, use: --limit @/Users/mpolgardi/ansible/test_playbook.retry

PLAY RECAP ********************************************************************************************************************
WIN-40NQ43PHHA5            : ok=3    changed=2    unreachable=0    failed=1  

有人可以帮我解码这个错误吗?我不知道在哪里看。还有一种方法让ansible给我可读的错误消息吗?

amazon-web-services web service ansible amazon
1个回答
0
投票

根据the fine manual,使用aws_s3_bucket_facts需要python同时使用botoboto3模块。

似乎正在发生的事情是,Windows机器正在尝试执行该.py文件,就像它是PowerShell一样,并且(当然)这两种语法完全不兼容。

你有ansible_python_interpreter设置为工作二进制文件?有可能将gather_facts:切换到yes会更早地表现出任何错误配置,虽然我不能发誓,因为我不知道winrm连接是否仅使用PowerShell抢占事实收集,并且不会注意到伪造的ansible_python_interpreter值。

虽然这不完全是你所问的,但是对于那些AWS-y任务使用delegate_to: localhost和/或connection: local也是一种常见的行为,因为在目标机器上运行这些任务几乎没有任何价值,因为凭证已存在于剧本中(即:它不会从目标计算机上的任何内容获取凭据)。当然,这假设您有一个本地python,其中安装了botoboto3,但这可能比说服随机Windows机器正常工作更有可能。

© www.soinside.com 2019 - 2024. All rights reserved.