我在使用我的剧本时遇到了一些问题:
这是声明,我不知道出了什么问题。
main.yml
- include: setup-ubuntu-trusty.yml
when: (ansible_distribution == "Ubuntu" and ansible_distribution_release == "trusty")
- include: setup-ubuntu-xenial.yml
when: (ansible_distribution == "Ubuntu" and ansible_distribution_release == "xenial")
当我运行此脚本时,它给了我这个错误
TASK: [utilities/requirements | requirements | include os-specific variables] ***
skipping: [ansible-test-vm02]
TASK: [utilities/requirements | requirements | install] ***********************
fatal: [ansible-test-vm02] => with_items expects a list or a set
FATAL: all hosts have already failed -- aborting
我使用的是Ubuntu xenial和两个变量的值(ansible_distribution = Ubuntu / ansible_distribution_release = xenial)
我不知道为什么我跳进第一个文件并给我错误。它应该跳过这个并进入xenial文件。
添加: 这是包含文件
setup-ubuntu-trusty.yml / setup-ubuntu-xenial.yml
- name: requirements | include os-specific variables
include_vars: "{{ ansible_distribution | lower }}-{{ ansible_distribution_release | lower }}.yml"
- name: requirements | install
apt: name={{ item }} state=present
with_items: "{{ package }}"
register: out_download
- name: requirements | output install
debug: var=out_download
答案 0 :(得分:1)
你能试试这个:
- include: setup-ubuntu-trusty.yml
when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'trusty'
- include: setup-ubuntu-xenial.yml
when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'xenial'