Learn Ansible
上QQ阅读APP看书,第一时间看更新

Installing common packages

Now that we have updated the installed packages, let's install the packages we want to install on all of the Linux servers we will be launching:

- name: install the common packages
yum:
name: "{{ item }}"
state: "installed"
with_items: "{{ common_packages }}"

As you can see, we are again using the yum module and we have added a descriptive name for the task. Rather than providing a list of packages in the task, we are using a variable called common_packages, which is defined in the roles/common/defaults/main.yml file as the following:

common_packages:
- "ntp"
- "ntpdate"
- "vim-enhanced"
- "git"
- "unzip"
- "policycoreutils-python"
- "epel-release"
- "https://centos7.iuscommunity.org/ius-release.rpm"

As you can see, we are installing ntp and ntpdate; we will be configuring ntp shortly. Next, we are installing vim-enhanced and git as they are always useful to have installed on a server. Then, we are installing the policycoreutils-python package, more on that later, before finally installing and enabling two additional yum repositories, EPEL and IUS.

Extra Packages for Enterprise Linux (EPEL) is a special interest group that maintains a collection of packages that are not part of the Red Hat Enterprise Linux core. EPEL packages are typically based on their Fedora counterparts and have been packaged so they will never conflict with, or replace, packages in the core Enterprise Linux distributions.

CentOS 7 ships with a package called epel-release, which enables the EPEL repository. However, there is no release package for IUS, so here, rather than using a package that is a part of the core CentOS repository, we are providing the full URL of the RPM file that enabled the IUS repository for CentOS 7.

The IUS Community Project is a collection of RPMs for Red Hat Enterprise Linux and compatible operating systems, such as CentOS, which aims to provide packages that are Inline with Upstream Stable, hence IUS. They provide packages for Apache, PHP, and MariaDB, which are all the latest release. The packages supplied by IUS adhere to the rules laid out in the SafeRepo Initiative, meaning they can be trusted.