我试图统一我安装软件包的方式,我有以下
vars/main.yml:
---
packages:
system:
common:
- crudini
- dump
- duplicity
- git
- mdadm
- irssi
- lynx
- postfix
- powerline
- rsync
- tmux
- vim
Debian:
- ntp
Fedora:
- langpacks-en
- langpacks-nl
- livecd-tools
- rktime
- tmux-powerline
- tuned
- vim-powerline
以下任务:
- name: install ansible dependencies
package: name={{ item }} state=present
with_flattened:
- "{{ packages.system.common }}"
- "{{ packages.system.Fedora }}"
- "{{ vars['packages.system.' + ansible_distribution] }}"
when: ansible_distribution == "Fedora"
tags:
install_custom2
导致以下错误:
TASK [common : install ansible dependencies] *******************************************************************************************
fatal: [host]: FAILED! => {"msg": "'dict object' has no attribute u'packages.system.Fedora'"}
请注意,"{{ packages.system.Fedora }}"
工作正常但"{{ vars['packages.system.' + ansible_distribution] }}"
失败(也会扩展为packages.system.Fedora
)。它看起来像是一个类型错误。当我将vars / main.yml中的包名称组织为单独的列表时,它确实有效。但我想创建这个字典结构,因为它很好地组织了变量。有没有办法像列表变量一样动态扩展字典变量?
答案 0 :(得分:0)
知道了,它适用于:"{{ packages.system[ansible_distribution] }}"