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

时间:2019-11-11 08:45:59

标签: ansible

我是ansible的新手,正在尝试运行多个任务以在ansible剧本中的特定主机组上安装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

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

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

我在这里做什么错了?

谢谢

1 个答案:

答案 0 :(得分:3)

它不是$ python3 module2.py m2: before: m2.G_VAR: default m1.call_G_VAR_changer m1: before: m2.G_VAR: default m2.G_VAR_changer m1: after: m2.G_VAR: changed # it seems it managed to change the value m2: after: m2.G_VAR: default # !!! but it failed to change it ,而是apt-key。请更新并重试