2

I inherited this ansible git from my predecessor. I can't get it to work though and I guess it's something basic that I'm missing. It keeps giving me this lovely error: ERROR! The tasks/main.yml file for role 'common' must contain a list of tasks

Ansible then proceeds to point to the very first char of the first line of my common/tasks/main.yml (By the way I have env vars to point to the right Ansible dir and the config, no idea if this be a cause)

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

Structure:

+-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

I guess that the important files are playbooks/basic.yml and playbooks/roles/common/tasks/main.yml

playbooks/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
Frank Vermeulen
  • 157
  • 2
  • 8
  • If you still having figured this out, I suggest re-running ansible with more verbosity. `ansible-playbook name.yml -vvv`. You might also want to check the encoding for your file. Open it with a text editor and force it to be utf8 with unix-style line-endings. – Zoredache Mar 13 '19 at 20:57

1 Answers1

2

Syntax of roles/common/tasks/main.yml is OK. You can try

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

Test the playbook

# ansible-lint basic.yml

To be sure I'd recommend to remove the sequence of 3 dots "..." from the name of the task.

- name: Installing Samba and etc
  apt: 

Quoting from YAML Basics

YAML files can optionally begin with --- and end with ... . This is part of the YAML format and indicates the start and end of a document.

Vladimir Botka
  • 5,138
  • 8
  • 20
  • Thanks for the advice @Vladimir. I tried pip install ansible-lint but couldn't get it working. There seems to be a problem on a fresh install ubuntu on windows subsystem and it tries to include the ansible Templar package twice.. I'll see if I can find a quick fix, but I don't want to keep on stacking issues :) – Frank Vermeulen Mar 12 '19 at 14:14
  • At Ubuntu 18.04 all works out of the box (ansible 2.7.7-1ppa~bionic, ansible-lint 3.4.20+git.20180203-1). Avoid pip and regularly upgrade packages (apt update; apt upgrade). – Vladimir Botka Mar 12 '19 at 16:12
  • You can also pass "--syntax-check" when you run the playbook. – Brett Levene Mar 12 '19 at 16:43
  • "--syntax-check" (perform a syntax check on the playbook, but do not execute it) is not going to help you here. There must be additional problem, not found by the syntax check (Error ... "may be elsewhere in the file depending on the exact syntax problem") . ansible-lint may, but doe not have to found it either. – Vladimir Botka Mar 12 '19 at 17:00
  • Indeed, @Vladimir is right, --syntax-check seems useful, but here it doesn't provide more details. And unfortunately I'm still on Ubuntu 16, I tried pip --upgrade and now pip isn't even working. I'm going to reinstall the machine tomorrow, try for 18 – Frank Vermeulen Mar 12 '19 at 19:05
  • The one thing I would do is make sure the indentation spaces are identical. For example, in main.yml you have a mixture of 2 and 4 spaces for indentation levels, that breaks things. – Brett Levene Mar 12 '19 at 19:59
  • No. It does not break the syntax. It's valid [YAML](https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#yaml-basics). You might want to cut&paste and test it "ansible-lint main.yml". – Vladimir Botka Mar 12 '19 at 20:58
  • I finally found the solution. However strange it seems. I reinstalled my WSL machine on ubuntu 18.04 and downloaded the git again. It still gave me the same error but I could install ansible-lint and run it. It pointed me towards a space after apt: on line 3. Removing the space validated the yml and I could run the playbook. Thanks VladimirBotka, @BrettLevene and Zoredache for handing me the tools to learn! – Frank Vermeulen Mar 15 '19 at 22:48