为什么ec2_ami抱怨未知参数WaiterConfig?

时间:2018-04-05 16:10:26

标签: ansible ec2-ami

我正在尝试使用Ansible的ec2_ami模块从EC2实例创建AMI。为此,我正在运行这个角色:

---
- name: Stop instance
  ec2:
    instance_id: "{{ instanceId }}"
    region: "{{ region }}"
    state: stopped
    wait: yes

- name: Create AMI
  ec2_ami:
    region: "{{ region }}"
    instance_id: "{{ instanceId }}"
    name: "{{ asg_name }}-{{ ansible_date_time.iso8601 | regex_replace('[^a-zA-Z0-9]', '-') }}"
    wait: yes
    state: present
  register: ami

我收到此错误:

Traceback (most recent call last):
  File "/tmp/ansible_zO2i0P/ansible_module_ec2_ami.py", line 701, in <module>
    main()
  File "/tmp/ansible_zO2i0P/ansible_module_ec2_ami.py", line 697, in main
    create_image(module, connection)
  File "/tmp/ansible_zO2i0P/ansible_module_ec2_ami.py", line 470, in create_image
    waiter.wait(ImageIds=[image_id], WaiterConfig=dict(Delay=delay, MaxAttempts=max_attempts))
  File "/usr/local/lib/python2.7/dist-packages/botocore/waiter.py", line 53, in wait
    Waiter.wait(self, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/botocore/waiter.py", line 295, in wait
    response = self._operation_method(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/botocore/waiter.py", line 84, in __call__
    return self._client_method(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 159, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 470, in _make_api_call
    api_params, operation_model, context=request_context)
  File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 523, in _convert_to_request_dict
    api_params, operation_model)
  File "/usr/local/lib/python2.7/dist-packages/botocore/validate.py", line 270, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "WaiterConfig", must be one of: DryRun, ImageIds, Owners, ExecutableUsers, Filters

我在Linux Ubuntu 14.04上运行Ansible 2.5.0版。这些是我安装的boto模块:

boto==2.45.0
boto3==1.7.0
botocore==1.4.50

我猜我有版本问题,但我不确定它是什么。此角色之前已运行,但我从版本2.0升级了Ansible。

4 个答案:

答案 0 :(得分:3)

问题是botocore需要升级。

sudo pip install awscli botocore boto3 -U

现在我的boto版本是

boto==2.45.0
boto3==1.7.0
botocore==1.10.0

角色运转良好。

答案 1 :(得分:2)

我告诉任务不要等待

# CREATE THE AMI IMAGE
- name: Create AMI Image from the instance just created
  local_action:
    module: ec2_ami
    instance_id: "{{ ec2_id }}"
    wait: no

并且“waiterconfig”错误消息消失了。

如果您想检查AMI图像创建的进度,因为您不再等待任务:

- name: Check the created AMI Image exists
  local_action:    
    module: ec2_ami_facts
    owners: self
    region: "{{ region }}"
    aws_access_key: "{{ aws_akey }}"
    aws_secret_key: "{{ aws_skey }}"        
    filters:
        "tag:Name": "NameOfAMI"
        "tag:ami_completeness": "someOtherTag"
  register: ami_find
  until: ami_find.images|length > 0
  retries: 5
  delay: 10

这将检查每10秒,对于5次检查,以查看AMI是否在结果中出现。如果有1,则长度大于0.您需要在过滤器中非常具体,以便在创建ami后只有一个结果。

答案 2 :(得分:1)

在Ansible 2.5上,按照有关更新awscli,boto3和botocore的说明进行操作,问题仍然存在。

TASK [Create AMI Image from the instance just created] ***********************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Unknown parameter in input: "WaiterConfig", must be one of: DryRun, ImageIds, Owners, ExecutableUsers, Filters
fatal: [a_flap_prod_door_21841_a -> localhost]: FAILED!

pip模块

 - awscli==1.15.2
 - boto==2.48.0 
 - boto3==1.7.2 
 - botocore==1.10.2

创建了AMI,但没有创建任何标记。这在Ansible 2.4上不是问题。

这可以通过告诉任务不要等待来解决:

# CREATE THE AMI IMAGE
- name: Create AMI Image from the instance just created
  local_action:
    module: ec2_ami
    instance_id: "{{ ec2_id }}"
    wait: no

并且它已经完成 - 没有错误并且标签已经创建

答案 3 :(得分:0)

这确实是Ansible 2.5的问题。这是GitHub上的错误报告:https://github.com/ansible/ansible/issues/40303

您可以应用其他答案中发布的解决方法,也可以仅返回2.4分支,直到问题解决:

pip install ansible==2.4.5

这将删除您当前的Ansible版本并安装版本2.4.5。

请注意,在撰写本文时,2.4.5是2.4分支上的最新版本。您可能要在Ansible 2.4 Changelog中查找最新版本,然后安装该版本。