首页 > 解决方案 > 稳定 | 错误!任务中未检测到任何操作。这通常表示模块名称拼写错误或模块路径不正确

问题描述

下面是 Ansible 脚本,它将删除现有的 Zip 文件(如果存在),使用 python 命令生成 src html 文件,生成 html 文件后,脚本将压缩它们:-

---
- name: run playbook locally
  hosts: 127.0.0.1
  connection: local
  become: yes
  gather_facts: yes
  tasks:
    - name: "CODE | PyDoc | Delete Zip"
      file:
        path: "{{ code_source_dev }}/doc/pydoc.zip"
        state: absent

    - name: CODE | Doc | Generating src html documents
      shell: "python -m pydoc -w src/*.py"
      ignore_errors: yes
      args:
          chdir: "{{ code_source_dev }}"
          executable: /bin/bash


    - name: CODE | Doc | Generating injectionModules html documents
      shell: "python -m pydoc -w injectionModules/*.py"
      ignore_errors: yes
      args:
          chdir: "{{ code_source_dev }}"
          executable: /bin/bash

    - name: CODE | Doc | Generating Test cases html documents
      shell: "python -m pydoc -w test/template_unit_test_framework.py"
      ignore_errors: yes
      args:
          chdir: "{{ code_source_dev }}"
          executable: /bin/bash

    - name: CODE | Doc | Zip html documents
      shell: "zip -r code-pydoc/pydoc.zip *.html"
      ignore_errors: yes
      args:
          chdir: "{{ code_source_dev }}"
          executable: /bin/bash

Ansible 命令:-

ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -K acm/plays/emr/pydocs.yml

从 Jenkins 执行后出现以下错误日志:-

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in '/data/jenkins/workspace/cng-tesie-master-ci/acm/plays/emr/pydocs.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: run playbook locally
  ^ here

使用的 Ansible 版本:-

+ ansible-playbook --version
ansible-playbook 2.7.5
  config file = None
  configured module search path = [u'/home/ec2-user/.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, Sep 12 2018, 05:31:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

标签: ansibleansible-2.x

解决方案


播放规范没有“名称”字段。所以这是错误的:

- name: run playbook locally
  hosts: 127.0.0.1
  connection: local
  become: yes
  gather_facts: yes
  tasks:

它应该看起来像这样:

- hosts: 127.0.0.1
  connection: local
  become: yes
  gather_facts: yes
  tasks:

推荐阅读