Hello all,
After running the command "ansible-doc yum", toward the end of the output, there are some nice example snippets regarding the use of the "yum" module in a playbook.
One of the examples is the following:
- name: Download the nginx package but do not install it
yum:
name:
- nginx
state: latest
What's prompting a question from me is the "nginx" package name being shown as a list item (- nginx). Is there any functional difference between the package name being
shown in the form of:
name: nginx
versus
name:
- nginx
If so, what do I gain by showing the package name as a list item? Another example
in that same output (ansible-doc yum) is the following:
- name: Install a list of packages
yum:
name:
- nginx
- postgresql
- postgresql-server
state: present
I can connect with that example, There are three packages to be operated on, and it makes sense (to me) to use a "list".
Okay, a little help here.
Hope everyone is safe and well!!!
Hi
No problem to use one line form here:
- name: Install a list of packages
yum:
name: [nginx,postgresql,postgresql-server]
state: present
Hi Trevor,
AFAIK, there should not be any significant difference. The yum module supports both a string and a list. So you can choose to use the short syntax you provided here with no problems at all.
It is not recommended however to loop the yum module.
- name: install packages
yum:
name: "{{ item }}"
state: latest
loop:
- nginx
- postgresql
- postgresql-server
Would run the yum module once for each package in the list (so three times in this example), where
- name: Install packages
yum:
name:
- nginx
- postgresql
- postgresql-server
state: latest
Would run the yum module a single time to install all packages at once.
Hi
No problem to use one line form here:
- name: Install a list of packages
yum:
name: [nginx,postgresql,postgresql-server]
state: present
Thanks Alexandre for your reply. Your information has advanced my understanding of YAML because I was not aware of the form that you provided. Thank you for that.
I'm still not clear if there is something different in the funtionality of:
name: nginx
versus
name:
- nginx
Again, thank you advancing my YAML knowledge.
Hi Trevor,
AFAIK, there should not be any significant difference. The yum module supports both a string and a list. So you can choose to use the short syntax you provided here with no problems at all.
It is not recommended however to loop the yum module.
- name: install packages
yum:
name: "{{ item }}"
state: latest
loop:
- nginx
- postgresql
- postgresql-server
Would run the yum module once for each package in the list (so three times in this example), where
- name: Install packages
yum:
name:
- nginx
- postgresql
- postgresql-server
state: latest
Would run the yum module a single time to install all packages at once.
Hello Metsie,
Many thanks for your response to my query, and for the
additional information as well.
Hope you're safe and well!!!
Trevor
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.