Hello. I am new to Ansible. Is there a way to create a dynamic array called packages.
I currently have the following blow, but I would like to just have it called packages, depending on debian or redhat, and if another OS, packages is empty.
vars:
- packages_debian:
- dash
- bash
- ksh
- tcsh
- gawk
- perl
- python
- php5-cli
- ruby
- tcl8.5
- packages_redhat:
- dash
- bash
- ksh
- tcsh
- gawk
- perl
- python
- php-cli
- ruby
- tcl
I solved it, but if there is better solution for this.
vars:
- packages:
- dash
- bash
- ksh
- tcsh
- gawk
- perl
- python
- php5-cli
- ruby
- tcl8.5
when: ansible_os_family == “Debian”
- packages:
- dash
- bash
- ksh
- tcsh
- gawk
- perl
- python
- php-cli
- ruby
- tcl
when: ansible_os_family == “RedHat”
test again, this should just make the 2nd definition overwrite the
first, you can do this with include_vars: "{{ansible_os_family}}.yml"
and have the definition of each in a file or you can do this:
vars:
- packages:
Debian:
- dash
- bash
- ksh
- tcsh
- gawk
- perl
- python
- php-cli
- ruby
- tcl
Redhat:
- dash
- bash
- ksh
- tcsh
- gawk
- perl
- python
- php5-cli
- ruby
- tcl8.5
and access it via packages[ansible_os_family]