ansans-错误!任务中未检测到任何操作

问题描述 投票:0回答:1

来自下面的剧本:

---
- name: Todobackend deployment playbook
  hosts: localhost
  connection: local
  gather_facts: no
  vars_files:
    - secrets.yml
  environment:
    AWS_DEFAULT_REGION: "{{ lookup('env', 'AWS_DEFAULT_VERSION') | default('us-west-2', true) }}"
  tasks:
    - include: tasks/create_stack.yml
    - include: tasks/deploy_app.yml

下面是应用程序部署任务模板(tasks/deploy.yml):

---
- name: set task definition facts
  set_fact:
    todobackend_task_def_arn:
      "{{ cf_stack.stack_outputs.TodobackendTaskDefinition | regex_replace('^(.*):[\\d]*$', '\\1') }}"
    todobackend_adhoc_task_def_arn:
      "{{ cf_stack.stack_outputs.TodobackendAdhocTaskDefinition | regex_replace('^(.*):[\\d]*$', '\\1') }}"

- name: update task definition
  aws_ecs_taskdefintion:
    state: update
    arn: "{{ item }}"
    containers:
      - name: todobackend
        image: "{{ image_tag }}"
  with_items:
    - "{{ todobackend_task_def_arn }}"
    - "{{ todobackend_adhoc_task_def_arn }}"
  when: image_tag is defined

- name: run migrations
  aws_ecs_task:
    operation: run
    cluster: "{{ cf_stack.stack_outputs.EcsCluster }}"
    task_definition: "{{ todobackend_adhoc_task_def_arn }}"
    count: 1
    overrides:
      containerOverrides:
        - name: todobackend
          command:
          - "manage.py"
          - "migrate"
          - "--noinput"
  register: migration_task
  when: ('migrate' in ecs_tasks | default([]))

- block:
  - debug: msg= {{ migration_task }}
    when: debug is defined
  - name: "fail if migration task failed"
    fail: msg="One or more migration tasks exited with non-zero exit code"
    with_items: "{{ migration_task.task | default([])}}"
    when: item.containers[0].exitCode != 0
  when: migration_task is defined

- name: run collectstatic
  aws_ecs_task:
    operation: run
    cluster: "{{ cf_stack.stack_outputs.EcsCluster }}"
    task_definition: "{{ todobackend_adhoc_task_def_arn }}"
    count: "{{ instance_count | default(1) }}"
    overrides:
      containerOverrides:
        - name: todobackend
          command:
          - "manage.py"
          - "migrate"
          - "--noinput"
  register: collectstatic_task
  when: ('collectstatic' in ecs_tasks | default([]))

- block:
  - debug: msg= {{ collectstatic_task }}
    when: debug is defined
  - name: "fail if collectstatic task failed"
    fail: msg="One or more collectstatic tasks exited with non-zero exit code"
    with_items: "{{ collectstatic_task.task | default([])}}"
    when: item.containers[0].exitCode != 0
  when: collectstatic_task is defined

- name: configure ecs service
  aws_ecs_service:
    state: update
    name: "{{ cf_stack.stack_outputs.TodobackendService }}"
    cluster: "{{ cf_stack.stack_outputs.EcsCluster }}"
    task_definition: "{{ todobackend_task_def_arn }}"
    desired_count: "{{ instance_count | default(1) }}"
    deployment_config:
      minimumHealthyPercent: 50
      maximumPercent: 200
  register: configure_ecs_service
  when: stack_config is defined

- debug: msg={{ configure_ecs_service }}
  when: configure_ecs_service is defined  and debug is defined

- name: deploy service update
  aws_ecs_service:
    state: update
    name: "{{ cf_stack.stack_outputs.TodobackendService }}"
    cluster: "{{ cf_stack.stack_outputs.EcsCluster }}" 
    task_definition: "{{ todobackend_task_def_arn }}"
  register: update_ecs_service
  when: image_tag is defined
- debug: msg={{ update_ecs_service }}
  when: update_ecs_service is defined and debug is defined  

以下命令出现错误:

$ ansible-playbook site.yml --ask-vault-pass -e '{"ecs_tasks":["migrate","collectstatic"],"stack_config":"true","debug":"true"}'
Vault password: 
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

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

The error appears to have been in '/home/user/../tasks/deploy_app.yml': line 9, column 3, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: update task definition
  ^ here

文件夹结构:

$ ls -R
.:
group_vars  library  secrets.yml  site.retry  site.yml  tasks  templates

./group_vars:
all

./library:
aws_ecs_service.py  aws_ecs_taskdefinition.py  aws_ecs_task.py

./tasks:
create_stack.yml  deploy_app.yml

./templates:
stack.yml
$
$
$ ansible --version
ansible 2.5.1
$
$

here是完整的代码

如何解决“更新任务定义”任务中的此错误?

amazon-web-services ansible amazon-cloudformation amazon-ecs ansible-2.x
1个回答
0
投票

模块名称拼写错误(最后一个,但缺少一个'i')。正确

- name: update task definition
  aws_ecs_taskdefinition:

© www.soinside.com 2019 - 2024. All rights reserved.