我正在尝试统一安装包的方式,我有以下几点
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中的包名组织为单独的列表时,它确实可以工作。但是我想创建这个字典结构,因为它很好地组织了变量。有没有办法像列表变量一样动态扩展字典变量?
发布于 2018-05-03 18:29:25
明白了,它可以和:"{{ packages.system[ansible_distribution] }}"一起工作
https://stackoverflow.com/questions/50151711
复制相似问题