Reputation: 2295
While it's possible to install a list of software the following way:
- name: Install what I want
apt:
name:
- docker
- nmap
Is it also possible to use a variable that contains a list of software names instead? Like so:
vars:
my_list:
- docker
- nmap
- name: Install what I want
apt:
name: "{{ my_list }}"
Upvotes: 2
Views: 1415
Reputation: 10163
I last ansible version you can use next syntax:
vars:
my_list: [docker, nmap]
tasks:
- name: Install APPS
apt:
name: "{{ my_list }}"
state: present
update_cache: yes
Upvotes: 2
Reputation: 68179
Yes. It's possible. name is "A list of package names". Both versions of the code are equivalent.
vars:
my_list:
- docker
- nmap
tasks:
- name: Install what I want
apt:
name: "{{ my_list }}"
vars:
my_list:
- docker
- map
tasks:
- name: Install what I want
apt:
name: "{{ item }}"
loop: "{{ my_list }}"
Upvotes: 6