Ansible

Ansible 錯誤:角色“common”的 tasks/main.yml 文件必須包含任務列表

  • March 15, 2019

我從我的前任那裡繼承了這個 ansible git。我無法讓它工作,我想這是我缺少的一些基本的東西。它不斷給我這個可愛的錯誤:ERROR! The tasks/main.yml file for role 'common' must contain a list of tasks

然後 Ansible 繼續指向我的 common/tasks/main.yml 第一行的第一個字元(順便說一下,我有 env vars 指向正確的 Ansible 目錄和配置,不知道這是否是一個原因)

ERROR! The tasks/main.yml file for role 'common' must contain a list of tasks

The error appears to have been in 
'/root/git/Ansible/playbooks/roles/common/tasks/main.yml': line 1, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: Installing Samba and etc...
^ here

結構:

+-Vault
+-playbooks/
 --basic.yml
 +-roles/
   +-common/
     +-handlers/main.yml
     +-tasks/main.yml
     +-templates/
       --krb5.conf.jinja2
       --realmd.conf.jinja2
       --smb.conf.jinja2
       --sssd.conf.jinja2
   +-join/tasks/main.yml
   +-prereq/tasks/main.yml

我猜重要的文件是playbooks/basic.ymlplaybooks/roles/common/tasks/main.yml

劇本/basic.yml

-  name: Install basic AD stuff
  hosts: all
  become: yes
  become_user: root
  gather_facts: no   
  vars_prompt:
     - name: "ad_admin_name"
       prompt: "username for AD join"
       private: no
     - name: "ad_admin_password"
       prompt: "password for AD"
       private: yes
       confirm: yes
  roles:
    - prereq
    - common
    - join
  #The End

playbooks/roles/common/tasks/main.yml

---
- name: Installing Samba and etc...
 apt: 
    name: "{{ packages }}"
    state: present
 vars:
    packages:
       - adcli
       - libnss-sss
       - libpam-sss
       - libwbclient-sssd
       - realmd
       - sssd
       - sssd-tools
       - samba
       - krb5-config
       - krb5-user
       - winbind
       - libpam-winbind
       - libnss-winbind
       - cifs-utils
- name: "template krb5.conf"
 template:
   src: "krb5.conf.jinja2"
   dest: "/etc/krb5.conf"
   owner: "root"
   group: "root"
   mode: "0644"
   backup: yes
- name: "template realmd.conf"
 template:
   src: "realmd.conf.jinja2"
   dest: "/etc/realmd.conf"
   owner: "root"
   group: "root"
   mode: "0644"
   backup: yes
- name: "template sssd.conf"
 template:
   src: "sssd.conf.jinja2"
   dest: "/etc/sssd/sssd.conf"
   owner: "root"
   group: "root"
   mode: "0600"
   backup: yes
 notify: "sssd needs restart"
- name: "template smb.conf"
 template:
   src: "smb.conf.jinja2"
   dest: "/etc/samba/smb.conf"
   owner: "root"
   group: "root"
   mode: "0644"
   backup: yes

roles/common/tasks/main.yml 的語法是可以的。你可以試試

# ansible-lint roles/common/tasks/main.yml

測試劇本

# ansible-lint basic.yml

可以肯定的是,我建議從任務名稱中刪除 3 個點“…”的序列。

- name: Installing Samba and etc
 apt: 

引用YAML 基礎知識

YAML 文件可以選擇以 — 開頭並以 … 結尾。這是 YAML 格式的一部分,指示文件的開始和結束。

引用自:https://serverfault.com/questions/957872