Ubuntu 20.04.2 / ansible 2.9.6 --- Never make it to correct yaml file syntax

lsepolis123

New Member
Credits
33
I tried over 35 times to edit yaml file(s) but again getting an error in the syntax:

Ubuntu 20.04.2 / ansible 2.9.6
book: Ubuntu-Linux-Bible 10e exercises page 632 / solutions page 696 - Chapter 28: Automating Apps and Infrastructure
with Ansible

[email protected]:~/Documents/Ubuntu-Linux-Bible 10e/ch28-ansible$ ansible-playbook -vC playbook.yml
Using /etc/ansible/ansible.cfg as config file
ERROR! Syntax Error while loading YAML.
did not find expected '-' indicator

The error appears to be in '/home/leonidas/Documents/Ubuntu-Linux-Bible 10e/ch28-ansible/playbook.yml': line 3, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Create web server
hosts: localhost
^ here
[email protected]:~/Documents/Ubuntu-Linux-Bible 10e/ch28-ansible$ ansible-playbook -vC playbook.yml
Using /etc/ansible/ansible.cfg as config file
ERROR! Syntax Error while loading YAML.
did not find expected '-' indicator

The error appears to be in '/home/leonidas/Documents/Ubuntu-Linux-Bible 10e/ch28-ansible/playbook.yml': line 3, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Create web server
hosts: localhost
^ here
[email protected]:~/Documents/Ubuntu-Linux-Bible 10e/ch28-ansible$
[email protected]:~/Documents/Ubuntu-Linux-Bible 10e/ch28-ansible$ ansible --version
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/leonidas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
[email protected]:~/Documents/Ubuntu-Linux-Bible 10e/ch28-ansible$ ansible-playbook -vC my_playbook4.yaml
Using /etc/ansible/ansible.cfg as config file
ERROR! Syntax Error while loading YAML.
found a tab character that violate indentation

The error appears to be in '/home/leonidas/Documents/Ubuntu-Linux-Bible 10e/ch28-ansible/my_playbook4.yaml': line 6, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Install Apache
apt:
^ here
There appears to be a tab character at the start of the line.

YAML does not use tabs for formatting. Tabs should be replaced with spaces.

For example:
- name: update tooling
vars:
version: 1.2.3
# ^--- there is a tab there.

Should be written as:
- name: update tooling
vars:
version: 1.2.3
# ^--- all spaces here.
[email protected]:~/Documents/Ubuntu-Linux-Bible 10e/ch28-ansible$



YAML:
# my_playbook3.yaml

---

- name: Create web server

  hosts: localhost

  tasks:

    - name: Install Apache

        apt:

          name: apache2

          state: present





# my_playbook2.yaml



---

- name: Create web server

    hosts: local

    remote_user: leonidas

    become_method: sudo

    become: yes

    tasks:

    - name: Install Apache

        apt:

          name: apache2

          state: present





# my_playbook1.yaml

---

- name: Create web server

hosts: localhost

become: yes

become_method: sudo

become_user: root

tasks:

- name: Install Apache

  apt:

    name: apache

    state: present
 
Last edited:
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Top