Create Dynamic Array Based on OS?

39 views
Skip to first unread message

Joaquin Menchaca

unread,
Jul 7, 2015, 1:34:56 PM7/7/15
to ansible...@googlegroups.com
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



Joaquin Menchaca

unread,
Jul 7, 2015, 1:47:58 PM7/7/15
to ansible...@googlegroups.com
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"


Brian Coca

unread,
Jul 7, 2015, 5:07:34 PM7/7/15
to ansible...@googlegroups.com
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]

--
Brian Coca
Reply all
Reply to author
Forward
0 new messages