下面是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)]
答案 0 :(得分:1)
播放规范没有“名称”字段。所以这是错误的:
- 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: