当尝试使用不存在的模块时,Ansible给出的错误信息不够明确

首先

我会记下来,因为我注意到 Ansible Playbook 在模块不存在的情况下的错误信息不太明确。

如果不注意,你可能会遇到看起来像是语法问题的错误信息的输出,这就是所谓的構文エラー。

环境

操作系统:CentOS 7.2.1511
Ansible(升级前):2.3.0.0
Ansible(升级后):2.4.2.0

$ ansible-playbook --version
ansible-playbook 2.3.0.0
  config file = /path/to/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

尝试使用的模块

ec2_vpc_endpoint 是一个用于创建和配置 Amazon VPC 终端节点的 Ansible 模块。详细信息请参考 http://docs.ansible.com/ansible/latest/ec2_vpc_endpoint_module.html。

2.4版本中的新功能。

这个ec2_vpc_endpoint模块只能在Ansible 2.4及以上版本中使用,但由于执行环境是2.3,所以无法使用。

试图执行Ansible Playbook

### ※途中省略
    # VPC Endpoint
    - name: Create new vpc endpoint the default policy
      ec2_vpc_endpoint:
        state: present
        region: ap-southeast-2
        vpc_id: vpc-12345678
        service: com.amazonaws.ap-southeast-2.s3
        route_table_ids:
          - rtb-12345678
          - rtb-87654321
      register: new_vpc_endpoint

运行时错误

在Ansible Playbook 2.3中,当尝试运行上述Playbook时,会输出以下错误消息。
一开始检查,看起来像是语法错误的信息,所以不得不多次检查Playbook。

$ ansible-playbook aws-net_vpc-with-endpoints.yml -C -vvv

Using /path/to/ansible.cfg as config file
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in '/path/to/aws-net_vpc-with-endpoints.yml': line 54, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

    # VPC Endpoint
    - name: Create new vpc endpoint the default policy
      ^ here


The error appears to have been in '/path/to/aws-net_vpc-with-endpoints.yml': line 54, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

    # VPC Endpoint
    - name: Create new vpc endpoint the default policy
      ^ here

将Ansible进行升级(从2.3升级到2.4)

$ sudo yum update ansible
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.riken.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.3.0.0-3.el7 will be updated
---> Package ansible.noarch 0:2.4.2.0-1.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================================
 Package                                   Arch                                     Version                                            Repository                              Size
====================================================================================================================================================================================
Updating:
 ansible                                   noarch                                   2.4.2.0-1.el7                                      epel                                   7.6 M

Transaction Summary
====================================================================================================================================================================================
Upgrade  1 Package

Total download size: 7.6 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
ansible-2.4.2.0-1.el7.noarch.rpm                                                                                                                             | 7.6 MB  00:00:11
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : ansible-2.4.2.0-1.el7.noarch                                                                                                                                     1/2
  Cleanup    : ansible-2.3.0.0-3.el7.noarch                                                                                                                                     2/2
  Verifying  : ansible-2.4.2.0-1.el7.noarch                                                                                                                                     1/2
  Verifying  : ansible-2.3.0.0-3.el7.noarch                                                                                                                                     2/2

Updated:
  ansible.noarch 0:2.4.2.0-1.el7

Complete!
$ ansible-playbook --version
ansible-playbook 2.4.2.0
  config file = /path/to/ansible.cfg
  configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

搞定!

$ ansible-playbook aws-net_vpc-with-endpoints.yml -C -vvv
※途中省略

PLAY RECAP *************************************************************************************************************************************************************************
localhost                  : ok=9    changed=1    unreachable=0    failed=0

教训

确保检查模块的兼容版本。

广告
将在 10 秒后关闭
bannerAds