如何在本地 运行 Ansible?

How to run Ansible locally?

我正在使用 Ansible 版本 2.2.0.0。

我的 Ansible 目录结构如下:

├── group-vars
│   └── kafka.yml
├── inventory
│   └── kafka
├── kafka.yml
└── roles
    └── kafka
        └── tasks
            ├── install.yml
            ├── main.yml
            └── verification.yml

1. kafka.yml 在组变量中

software_dir: /home/sohanvir/softwares
kafka_installation_dir: "{{ software_dir }}/kafka"

kafka_version: kafka_2.11-0.10.1.0.tgz
kafka_download_link: "http://redrockdigimark.com/apachemirror/kafka/0.10.1.0/{{ kafka_version}}"

2。库存==>卡夫卡

[kafka]
localhost

3。剧本==> kafka.yml

- name: Install Kafka
  hosts: kafka
  connection: local
  roles:
    - kafka

4。角色==>卡夫卡==>任务

1. main.yml

- include: verification.yml
- include: main.yml

2。 install.yml

- name: Download kafka from link
  get_url:
    url: '{{ kafka_download_link }}'
    dest: '{{ kafka_installation_dir }}'

- name: Extract tar file
  shell: cd '{{ kafka_installation_dir }}' && tar -xzf '{{ kafka_2.11-0.10.1.0.tgz }}'

3。 verification.yml

- name: Verify Directory Structure
  shell: mkdir -p '{{ kafka_installation_dir }}'
  ignore_errors: no

我是 运行 剧本,使用以下命令:

 ansible-playbook -i inventory/kafka kafka.yml 

但出现以下错误:

PLAY [Install Kafka] ***********************************************************
TASK [setup] ******************************************************************* ok: [localhost]
TASK [kafka : Verify Directory Structure] ************************************** fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'kafka_installation_dir' is undefined\n\nThe error appears to have been in '/home/sohanvir/personal_git/ansible/roles/kafka/tasks/verification.yml': line 1, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Verify Directory Structure\n ^ here\n"} to retry, use: --limit @/home/sohanvir/personal_git/ansible/kafka.retry
PLAY RECAP ********************************************************************* localhost : ok=1 changed=0 unreachable=0 failed=1

将目录名称 group-vars 更改为 group_vars

Splitting Out Host and Group Specific Data'