Ansible Module yum: Difference between revisions
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
=Examples= | =Examples= | ||
Install a | ==Install a Single Package== | ||
<syntaxhighlight lang='yaml'> | <syntaxhighlight lang='yaml'> | ||
- name: install the latest version of Apache | - name: install the latest version of Apache | ||
Line 12: | Line 12: | ||
state: latest | state: latest | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Install a list of packages: | ==Install a List of Packages== | ||
For that, declare a variable containing the list of packages, and use the variable name in the "name:" configuration element. | |||
⚠️ When used with a loop: each package will be processed individually, it is much more efficient to pass the list directly to the name option. | |||
<syntaxhighlight lang='yaml'> | <syntaxhighlight lang='yaml'> | ||
- name: | - name: Install a list of packages | ||
vars: | vars: | ||
packages: | packages: | ||
- httpd | - httpd | ||
- httpd-tools | - httpd-tools | ||
become: true | |||
become_method: sudo | |||
yum: | |||
name: "{{ packages }}" | |||
</syntaxhighlight> | |||
Alternative: | |||
<syntaxhighlight lang='yaml'> | |||
- name: Install a list of packages | |||
become: true | |||
become_method: sudo | |||
yum: | |||
name: | |||
- nginx | |||
- postgresql | |||
- postgresql-server | |||
state: present | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Other | ==Other Examples== | ||
<syntaxhighlight lang='yaml'> | <syntaxhighlight lang='yaml'> | ||
- name: remove the Apache package | - name: remove the Apache package | ||
Line 86: | Line 102: | ||
name: sos | name: sos | ||
disablerepo: "epel,ol7_latest" | disablerepo: "epel,ol7_latest" | ||
- name: Download the nginx package but do not install it | - name: Download the nginx package but do not install it |
Latest revision as of 04:34, 13 April 2021
External
Internal
Overview
Examples
Install a Single Package
- name: install the latest version of Apache
yum:
name: httpd
state: latest
Install a List of Packages
For that, declare a variable containing the list of packages, and use the variable name in the "name:" configuration element. ⚠️ When used with a loop: each package will be processed individually, it is much more efficient to pass the list directly to the name option.
- name: Install a list of packages
vars:
packages:
- httpd
- httpd-tools
become: true
become_method: sudo
yum:
name: "{{ packages }}"
Alternative:
- name: Install a list of packages
become: true
become_method: sudo
yum:
name:
- nginx
- postgresql
- postgresql-server
state: present
Other Examples
- name: remove the Apache package
yum:
name: httpd
state: absent
- name: install the latest version of Apache from the testing repo
yum:
name: httpd
enablerepo: testing
state: present
- name: install one specific version of Apache
yum:
name: httpd-2.2.29-1.4.amzn1
state: present
- name: upgrade all packages
yum:
name: '*'
state: latest
- name: upgrade all packages, excluding kernel & foo related packages
yum:
name: '*'
state: latest
exclude: kernel*,foo*
- name: install the nginx rpm from a remote repo
yum:
name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present
- name: install nginx rpm from a local file
yum:
name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
state: present
- name: install the 'Development tools' package group
yum:
name: "@Development tools"
state: present
- name: install the 'Gnome desktop' environment group
yum:
name: "@^gnome-desktop-environment"
state: present
- name: List ansible packages and register result to print with debug later.
yum:
list: ansible
register: result
- name: Install package with multiple repos enabled
yum:
name: sos
enablerepo: "epel,ol7_latest"
- name: Install package with multiple repos disabled
yum:
name: sos
disablerepo: "epel,ol7_latest"
- name: Download the nginx package but do not install it
yum:
name:
- nginx
state: latest
download_only: true