我试图运行一本剧本以自动化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:Temptest.conf
win_file:
path: C:Temptest.conf
state: touch
- name: Create another file to C:Temptest2.conf
win_file:
path: C:Temptest2.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:Temptest.conf] *************************************************************************************
changed: [WIN-40NQ43PHHA5]
TASK [Create another file to C:Temptest2.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 FAILUREnSee 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
有人可以帮助我解码此错误吗?我不知道在哪里看。还有一个方法可以让我提供可读的错误消息?
根据精美的手册,使用aws_s3_bucket_facts
需要使用boto
和boto3
模块的Python。
出现正在发生的事情是,Windows机器正试图执行.py
文件,就好像是PowerShell一样,(当然)这两个语法是完全不相容的。
您是否将ansible_python_interpreter
设置为工作二进制?可能的,将gather_facts:
切换到yes
会更早地浮出任何错误,尽管我不能发誓,因为我不知道winrm
连接是否会使用PowerShell进行事实收集,并且会t注意一个伪造的ansible_python_interpreter
值。
虽然这不是您问的内容,但使用delegate_to: localhost
和/或connection: local
作为这些AWS-y任务也是一个普遍的行为,因为拥有这些任务几乎没有价值鉴于凭证已经存在于剧本中(即:它不会从目标机器上的任何内容中获取凭据),因此在 target 机器上运行的任务。这自然可以假定您有一个本地Python,其中安装了boto
和boto3
,但这比说服随机的Windows机器正常工作的可能性更大。