Error a malformed block was encountered while loading a block

trying to run a playbook: --- - name: azure authorization hosts: localhost become: yes gather_facts: true tasks: - azure_authorization_configuration where task look like: --- - name...

trying to run a playbook:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

where task look like:

---
- name:
  stat: >
    path="{{ azure_subscription_authorization_configuration_file_dir }}"
  register: stat_dir_result
  tags:
    - azure

and defaults main file look like:

---
azure_subscription_authorization_configuration_file_dir: '~/.azure/'

Directories tree look like:

├── hosts
├── playbooks
│   └── azure_authorization_playbook.yml
├── roles
│   ├── az_auth
│   │   ├── defaults
│   │   │   └── main.yml
│   │   └── tasks
│   │       └── main.yml

Ansible version: 2.9.1
Ansible playbook command line snippet:

/> ansible-playbook "/Users/user/Dev/Ansible/playbooks/azure_authorization_playbook.yml"

Output:

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

ERROR! A malformed block was encountered while loading a block

Don’t have any idea which block was encountered while loading a which block, can anyone tell me where is the issue? Thanks!

trying to run a playbook:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

where task look like:

---
- name:
  stat: >
    path="{{ azure_subscription_authorization_configuration_file_dir }}"
  register: stat_dir_result
  tags:
    - azure

and defaults main file look like:

---
azure_subscription_authorization_configuration_file_dir: '~/.azure/'

Directories tree look like:

├── hosts
├── playbooks
│   └── azure_authorization_playbook.yml
├── roles
│   ├── az_auth
│   │   ├── defaults
│   │   │   └── main.yml
│   │   └── tasks
│   │       └── main.yml

Ansible version: 2.9.1
Ansible playbook command line snippet:

/> ansible-playbook "/Users/user/Dev/Ansible/playbooks/azure_authorization_playbook.yml"

Output:

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

ERROR! A malformed block was encountered while loading a block

Don’t have any idea which block was encountered while loading a which block, can anyone tell me where is the issue? Thanks!

1) Solution

The error is clearly coming from your playbook, because it doesn’t call any roles or load any other playbooks. That is, if I put this in a file:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

And try to run it, I get the same error. The issue is the entry in your tasks block. A task should be a dictionary, but you’ve provided only a string:

  tasks: 
    - azure_authorization_configuration

You include an example of a correctly written task in your question. If we put that into your playbook, it would look like:

- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - name:
      stat: >
        path="{{ azure_subscription_authorization_configuration_file_dir }}"
      register: stat_dir_result
      tags:
        - azure
2) Solution

I got this error because i had a syntax error in my playbook. Note the use of colons(‘:’) in your playbook.

3) Solution

Ok, now I know how my playbook should look like, it was:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

Should be:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  roles: 
    - azure_authorization_configuration
4) Solution

in my case it was the error in the role. i missed «:»

the wrong code

$ cat main.yml
---
# tasks file for db.local

- include pre_install.yml
- include my_sql.yml

the good code:

$ cat main.yml
---
# tasks file for db.local

- include: pre_install.yml
- include: my_sql.yml
5) Solution

How to ping windows and linux machines from ansible machine, Please provide steps.

Comments Section

Allright, now i managed to run this as I intent to. Swiching tasks with roles in my playbook. :)

Related Topics
ansible

Mentions
Alex
Larsks
Umesh
Thisissober Accounthere
Throws Error

References
stackoverflow.com/questions/59032399/ansible-malformed-block-was-encountered-while-loading-a-block

The following is my yaml file for a ansible configuration of a cisco device. In /etc/ansible/hosts I have also edited the hosts file to reflect my Amazon EC2 Ami instance as can be seen below

[ec2-instances]
ec2-54-152-72-23.compute-1.amazonaws.com

Inventory file ^

YAML File Below

---
-  hosts: ec2-54-152-72-23.compute-1.amazonaws.com
   gather_facts: false
   connection: local

   tasks:
    -name:  Customer IOS Upgrade Initial Discovery
    cli_command: "{{ show }}"

    vars: 
      show:
       - show run
       - show version
       - show interface status
       - show license


    -mail: 
      host: smtp.gmail.com
      port: 587
      username: sample@gmail.com
      password: sample2
      to: sample@sample.com
      subject: '{{ ansible_hostname }} configuration' 
      body: 'System {{ ansible_hostname }} has been successfully discovered.'
      delegate_to: localhost

    save_when: changed   
...

I get the following error message when trying to run the following. Any idea why this is happening? I have switched out what is seen in the initial .yaml file provided with [ec2-instances] and there is still no difference in runtime result.

ansible-playbook -i /etc/ansible/hosts test2.yml --user ec2-user --private-key=/home/adam/Desktop/EC2CSR1000v.pem -vvv
ansible-playbook 2.7.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/adam/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.15rc1 (default, Nov 12 2018, 14:31:15) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected
Parsed /etc/ansible/hosts inventory source with ini plugin
ERROR! A malformed block was encountered while loading tasks

The error appears to have been in '/etc/ansible/scripts/test2.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
-  hosts: [ec2-instance]
   ^ here

Questions : Ansible — malformed block was encountered while loading a block

2023-02-06T11:54:11+00:00 2023-02-06T11:54:11+00:00

678

trying to run a playbook:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

where task look like:

---
- name:
  stat: >
    path="{{ azure_subscription_authorization_configuration_file_dir }}"
  register: stat_dir_result
  tags:
    - azure

and defaults main file look like:

---
azure_subscription_authorization_configuration_file_dir: '~/.azure/'

Directories tree look like:

├── hosts
├── playbooks
│   └── azure_authorization_playbook.yml
├── roles
│   ├── az_auth
│   │   ├── defaults
│   │   │   └── main.yml
│   │   └── tasks
│   │       └── main.yml

Ansible version: 2.9.1
Ansible playbook help uvdos ansible command line snippet:

/> ansible-playbook "/Users/user/Dev/Ansible/playbooks/azure_authorization_playbook.yml"

Output:

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

ERROR! A malformed block was encountered while loading a block

Don’t have any idea which block was help uvdos ansible encountered while loading a which block, can help uvdos ansible anyone tell me where is the issue? Thanks!

Total Answers 4

25

Answers 1 : of Ansible — malformed block was encountered while loading a block

The error is clearly coming from your help uvdos ansible playbook, because it doesn’t call any help uvdos ansible roles or load any other playbooks. That help uvdos ansible is, if I put this in a file:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

And try to run it, I get the same error. help uvdos ansible The issue is the entry in your tasks help uvdos ansible block. A task should be a dictionary, help uvdos ansible but you’ve provided only a string:

  tasks: 
    - azure_authorization_configuration

You include an example of a correctly help uvdos ansible written task in your question. If we put help uvdos ansible that into your playbook, it would look help uvdos ansible like:

- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - name:
      stat: >
        path="{{ azure_subscription_authorization_configuration_file_dir }}"
      register: stat_dir_result
      tags:
        - azure

0

2023-02-06T11:54:11+00:00 2023-02-06T11:54:11+00:00Answer Link

mRahman

6

Answers 2 : of Ansible — malformed block was encountered while loading a block

I got this error because i had a syntax help uvdos ansible error in my playbook. Note the use of help uvdos ansible colons(‘:’) in your playbook.

0

2023-02-06T11:54:11+00:00 2023-02-06T11:54:11+00:00Answer Link

karim

2

Answers 3 : of Ansible — malformed block was encountered while loading a block

Ok, now I know how my playbook should help uvdos ansible look like, it was:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

Should be:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  roles: 
    - azure_authorization_configuration

0

2023-02-06T11:54:11+00:00 2023-02-06T11:54:11+00:00Answer Link

karim

6

Answers 4 : of Ansible — malformed block was encountered while loading a block

in my case it was the error in the role. help uvdos ansible i missed «:»

the wrong code

$ cat main.yml
---
# tasks file for db.local

- include pre_install.yml
- include my_sql.yml

the good code:

$ cat main.yml
---
# tasks file for db.local

- include: pre_install.yml
- include: my_sql.yml

0

2023-02-06T11:54:11+00:00 2023-02-06T11:54:11+00:00Answer Link

karim

Пытаюсь запустить playbook:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

Где задача выглядит так:

---
- name:
  stat: >
    path="{{ azure_subscription_authorization_configuration_file_dir }}"
  register: stat_dir_result
  tags:
    - azure

И по умолчанию основной файл выглядит так:

---
azure_subscription_authorization_configuration_file_dir: '~/.azure/'

Дерево каталогов выглядит так:

├── hosts
├── playbooks
│   └── azure_authorization_playbook.yml
├── roles
│   ├── az_auth
│   │   ├── defaults
│   │   │   └── main.yml
│   │   └── tasks
│   │       └── main.yml

Ansible версия: 2.9.1 Отрывок командной строки Ansible playbook:

/> ansible-playbook "/Users/user/Dev/Ansible/playbooks/azure_authorization_playbook.yml"

Выход:

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

ERROR! A malformed block was encountered while loading a block

Не знаю, с каким блоком столкнулись при загрузке какого блока, кто-нибудь может сказать мне, где проблема? Спасибо!

3 ответа

Лучший ответ

Хорошо, теперь я знаю, как должна выглядеть моя пьеса:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

Должно быть:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  roles: 
    - azure_authorization_configuration


0

thisissober accounthere
25 Ноя 2019 в 14:03

Ошибка явно исходит из вашего playbook, потому что он не вызывает никаких ролей и не загружает какие-либо другие playbook. То есть, если я помещу это в файл:

---
- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - azure_authorization_configuration

И попробуйте запустить его, я получаю ту же ошибку. Проблема заключается в записи в вашем блоке tasks. Задача должна быть словарем, но вы указали только строку:

  tasks: 
    - azure_authorization_configuration

Вы включаете в свой вопрос пример правильно написанного задания. Если мы поместим это в вашу книгу, это будет выглядеть так:

- name: azure authorization
  hosts: localhost
  become: yes
  gather_facts: true
  tasks: 
    - name:
      stat: >
        path="{{ azure_subscription_authorization_configuration_file_dir }}"
      register: stat_dir_result
      tags:
        - azure


0

larsks
25 Ноя 2019 в 13:35

Я получил эту ошибку, потому что у меня была ошибка синтаксиса в моей пьесе. Обратите внимание на использование двоеточий (‘:’) в вашей пьесе.


1

user12618100
29 Дек 2019 в 08:53

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Error a jnj error has occurred
  • Error a jni error has occurred please check your installation and try again сервер майнкрафт
  • Error a jni error has occurred please check your installation and try again ошибка
  • Error a jni error has occurred please check your installation and try again как решить
  • Error a jni error has occurred please check your installation and try again как исправить

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии