Ansible - 如何在剧本中运行多个任务

Kon*_*262 0 ansible

我是 ansible 的新手,并且正在尝试运行多个任务以在 ansible playbook 中的特定主机组上安装 docker。

我有以下剧本...

---
 - hosts: all
   tasks:
    - name: Update and upgrade apt packages
      become: yes
      apt:
        upgrade: yes
        update_cache: yes
        cache_valid_time: 86400 #One day

 - hosts: loadbalancer
   become: yes
   tasks:
    - name: Install docker packages
      apt:
        name:
        - 'apt-transport-https'
        - 'ca-certificates'
        - 'curl'
        - 'software-properties-common'
        state: present

    - name: Add Docker official GPG key
      apt-key:
        url: https://download.docker.com/linux/ubuntu/gpg
Run Code Online (Sandbox Code Playgroud)

这是我在尝试运行剧本时遇到的错误...

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

The error appears to be in '/home/vagrant/ansible/playbooks/hostname.yml': line 23, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


    - name: Add Docker official GPG key
      ^ here
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?

谢谢,

Smi*_*ily 5

不是apt-key,是apt_key。请更新并重试