Ansible 错误:角色“common”的 task/main.yml 文件必须包含任务列表

Ansible 错误:角色“common”的 task/main.yml 文件必须包含任务列表

我从我的前任那里继承了这个 ansible git。但我无法让它工作,我想这是我缺少的一些基本功能。它一直给我这个可爱的错误:ERROR! The tasks/main.yml file for role 'common' must contain a list of tasks

然后,Ansible 继续指向我的 common/tasks/main.yml 第一行的第一个字符(顺便说一下,我有环境变量来指向正确的 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

剧本/角色/常见/任务/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

答案1

语法: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 格式的一部分,表示文档的开始和结束。

相关内容