Ansible-加载块时遇到格式错误的块
正在尝试运行剧本:Ansible-加载块时遇到格式错误的块,ansible,Ansible,正在尝试运行剧本: --- - name: azure authorization hosts: localhost become: yes gather_facts: true tasks: - azure_authorization_configuration 任务看起来像: --- - name: stat: > path="{{ azure_subscription_authorization_configuration_file_dir }
---
- 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
- 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
默认情况下,主文件如下所示:
---
- 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
- 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
目录树看起来像:
---
- 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
- 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
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
不知道加载哪个块时遇到了哪个块,有人能告诉我问题出在哪里吗?谢谢 错误显然来自您的剧本,因为它不调用任何角色或加载任何其他剧本。也就是说,如果我把它放在一个文件中:
---
- name: azure authorization
hosts: localhost
become: yes
gather_facts: true
tasks:
- azure_authorization_configuration
试着运行它,我得到了同样的错误。问题是任务
块中的条目。任务应该是字典,但您只提供了字符串:
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
- 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
好的,现在我知道我的剧本应该是什么样子了,它是:
---
- 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
我犯了这个错误,因为我的剧本中有语法错误。注意在剧本中使用冒号(“:”)。在我的例子中,这是角色中的错误。我错过了“:” 错误的代码
$ cat main.yml
---
# tasks file for db.local
- include pre_install.yml
- include my_sql.yml
好代码:
$ cat main.yml
---
# tasks file for db.local
- include: pre_install.yml
- include: my_sql.yml
好了,现在我按照我的意图运行了这个。使用我的剧本中的角色切换任务。:)