错误!这个任务 'apt_repository' 有额外的参数

ERROR! this task 'apt_repository' has extra params

我第一次尝试使用 Ansible。当我尝试 运行 剧本时,我收到了这个错误:

ERROR! this task 'apt_repository' has extra params, which is only allowed in the following modules: command, shell, script, include, include_vars, add_host, group_by, set_fact, raw, meta

The error appears to have been in '/home/prism/Desktop/ansible/basic_package/main.yml': line 9, column 5, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


  - name: "Add Webupd8 ppa for youtube-dl"
    ^ here

main.yml :

---
- hosts: all
  remote_user: root

  tasks:
  - name: "Upgrade the whole system"
    apt: upgrade=dist update_cache=yes

  - name: "Add Webupd8 ppa for youtube-dl"
    apt_repository: repo ='ppa:nilarimogard/webupd8'

  - name: "Install basic package"
    apt: name={{ item }} state=installed
    with_items:
      - libffi-dev
      - vnstat
      - youtube-dl
      - finger
      - htop
      - python3-dev
      - axel
      - curl
      - fail2ban
      - python-dev
      - sendmail
      - git
      - python-software-properties
      - software-properties-common
      - python-pip
      - nethogs
      - unzip
      - nmap

看起来您在 apt_repository 任务中的 repo 参数后有一个额外的 space。使用以下代码:

apt_repository: repo='ppa:nilarimogard/webupd8'