首页 > 解决方案 > Ansible 看不到主机列表或角色

问题描述

当我运行 ansible-playbook -k configure-clish.yml 时,出现以下错误:

我认为这不是语法问题,因为 Visual Studio Code 中没有显示语法问题。

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

ERROR! the role 'ashwin_sid.gaia_fw1' was not found in /app/sandbox/playbooks/roles:/home/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/app/sandbox/playbooks

The error appears to be in '/app/sandbox/playbooks/configure-clish.yml': line 25, column 16, but may
be elsewhere in the file depending on the exact syntax problem.

违规行似乎是:

   'import_role:
     name: ashwin_sid.gaia_fw1
           ^ here'

这是剧本:

- hosts: localhost
   tasks:
    - command: /bin/echo "{{ lookup('pipe','date +%Y-%m-%d_%H-%M') }}"
      register: foo

    - file:
        path: ../SHOW
        state: directory

 - hosts: ckp
   serial: 1
   gather_facts: no
   tasks:
     - name: SHOW COMMAND
       import_role:
         name: ashwin_sid.gaia_fw1
         tasks_from: setclish
       vars:
         cmdfile: configure-clish.cmd
         logdir: ../SHOW

这是主机文件:

[ckp]
lab ansible_host=192.168.2.1

这是 ansible.cfg 文件:

[defaults]
roles_path = /app/sandbox/roles/ashwin_sid.gaia_fw1
inventory = /app/sandbox/hosts
host_key_checking = False
retry_files_enabled = False

标签: ansibleansible-inventory

解决方案


正如错误所说,您没有名为ashwin_sid.gaia_fw1. 确保该角色位于 /app/sandbox/playbooks/roles、/home/.ansible/roles、/usr/share/ansible/roles、/etc/ansible/roles 或 /app/sandbox/playbooks 中的某个位置以及您的问题应该修复。


推荐阅读