Как обновить ansible ubuntu

Обновлено: 02.07.2024

Ansible by default manages machines over the SSH protocol.

Once Ansible is installed, it will not add a database, and there will be no daemons to start or keep running. You only need to install it on one machine (which could easily be a laptop) and it can manage an entire fleet of remote machines from that central point. When Ansible manages remote machines, it does not leave software installed or running on them, so there’s no real question about how to upgrade Ansible when moving to a new version.

What Version To Pick?¶

Because it runs so easily from source and does not require any installation of software on remote machines, many users will actually track the development version.

Ansible’s release cycles are usually about four months long. Due to this short release cycle, minor bugs will generally be fixed in the next release versus maintaining backports on the stable branch. Major bugs will still have maintenance releases when needed, though these are infrequent.

If you are wishing to run the latest released version of Ansible and you are running Red Hat Enterprise Linux (TM), CentOS, Fedora, Debian, or Ubuntu, we recommend using the OS package manager.

For other installation options, we recommend installing via “pip”, which is the Python package manager, though other options are also available.

If you wish to track the development release to use and test the latest features, we will share information about running from source. It’s not necessary to install the program to run from source.

Control Machine Requirements¶

Currently Ansible can be run from any machine with Python 2 (version 2.7) or Python 3 (versions 3.5 and higher) installed. Windows isn’t supported for the control machine.

This includes Red Hat, Debian, CentOS, macOS, any of the BSDs, and so on.

macOS by default is configured for a small number of file handles, so if you want to use 15 or more forks you’ll need to raise the ulimit with sudo launchctl limit maxfiles unlimited . This command can also fix any “Too many open files” error.

Please note that some modules and plugins have additional requirements. For modules these need to be satisfied on the ‘target’ machine and should be listed in the module specific docs.

Managed Node Requirements¶

On the managed nodes, you need a way to communicate, which is normally ssh. By default this uses sftp. If that’s not available, you can switch to scp in ansible.cfg . You also need Python 2 (version 2.6 or later) or Python 3 (version 3.5 or later).

If you have SELinux enabled on remote nodes, you will also want to install libselinux-python on them before using any copy/file/template related functions in Ansible. You can use the yum module or dnf module in Ansible to install this package on remote systems that do not have it.

By default, Ansible uses the python interpreter located at /usr/bin/python to run its modules. However, some Linux distributions may only have a Python 3 interpreter installed to /usr/bin/python3 by default. On those systems, you may see an error like:

you can either set the ansible_python_interpreter inventory variable (see Working with Inventory ) to point at your interpreter or you can install a Python 2 interpreter for modules to use. You will still need to set ansible_python_interpreter if the Python 2 interpreter is not installed to /usr/bin/python.

Ansible’s “raw” module (for executing commands in a quick and dirty way) and the script module don’t even need Python installed. So technically, you can use Ansible to install a compatible version of Python using the raw module , which then allows you to use everything else. For example, if you need to bootstrap Python 2 onto a RHEL-based system, you can install it via

Он предоставляет вам легкую настройку для большого количества удаленных хостов.

Например, вы выполняете одни и те же задачи на нескольких компьютерах, Ansible предоставляет вам возможность автоматизировать эти задачи.

Этот учебник поможет вам установить Ansible на Ubuntu 18.04 (Bionic) LTS

Вы можете настроить ssh на основе ключей для удаленных хостов Linux Ansible.

Поэтому для SSH пароль не потребуется.

Ansible также позволяет использовать пароль для ssh, но основанный на ключах ssh более безопасен.

Создайте пару ssh-ключей на сервере Ansible:

Скопируйте открытый ключ на все удаленные хосты, которые необходимо подключить с помощью этого ключа ssh.

Ansible предоставляет официальный PPA для установки в системах Ubuntu.

Выполните следующую команду, чтобы настроить Ansible PPA в вашей системе Ubuntu 18.04.

После добавления репозитория Ansible выполните следующие команды для установки.

Ваш сервер с Ansible готов для удаленного управления хостами и автоматизации.

Вы можете иметь несколько хостов, которые вам нужны, и управлять ими с помощью одного сервера Ansible.

Здесь вам нужно определить свои удаленные системы в файле Ansible hosts (/etc/ansible/hosts). Вы также можете создавать группы хостов с похожими типами. Здесь вам необходимо правильно организовать свои хосты в группы. Группы используются для выполнения одной задачи на всех удаленных хостах, определенных под ней.

Измените файл конфигурации Ansible hosts:

Добавьте свои хосты и организуйте их группами. Хост может быть добавлен в несколько групп.

Картинка ниже поможет вам понять как организоны группы и хосты в группах.


Конфигурация единого хоста

Вам необходимо определить настройки для ваших хостов. Файл с конкретным хостом должен иметь то же имя, что и хост (например: web-host1) в каталоге host_vars.

Добавьте настройки SSH в этот файл для веб-хоста1.

Если вы не использовали настройки shh в шаге 1 , вы можете выполнить настройку аутентификации:

Конфигурация группы Vars

Имя файла группы должно быть таким же, как имя группы (например: webservers) в каталоге group_vars.

Добавьте общие переменные в этот файл, используемые всеми хостами, добавленными в эту группу.

Ваша установка Ansible готова к тестированию. Чтобы проверить подключение всех хостов с помощью модуля ping, выполните:

Проверить возможности подключения для определенного хоста или группы хостов:

Ansible is an agentless automation tool that you install on a control node. From the control node, Ansible manages machines and other devices remotely (by default, over the SSH protocol).

To install Ansible for use at the command line, simply install the Ansible package on one machine (which could easily be a laptop). You do not need to install a database or run any daemons. Ansible can manage an entire fleet of remote machines from that one control node.

Prerequisites

Before you install Ansible, review the requirements for a control node. Before you use Ansible, review the requirements for managed nodes (those end devices you want to automate). Control nodes and managed nodes have different minimum requirements.

Control node requirements

For your control node (the machine that runs Ansible), you can use any machine with Python 2 (version 2.7) or Python 3 (versions 3.5 and higher) installed. ansible-core 2.11 and Ansible 4.0.0 will make Python 3.8 a soft dependency for the control node, but will function with the aforementioned requirements. ansible-core 2.12 and Ansible 5.0.0 will require Python 3.8 or newer to function on the control node. Starting with ansible-core 2.11, the project will only be packaged for Python 3.8 and newer. This includes Red Hat, Debian, CentOS, macOS, any of the BSDs, and so on. Windows is not supported for the control node, read more about this in Matt Davis’s blog post.

Please note that some plugins that run on the control node have additional requirements. These requirements should be listed in the plugin documentation.

When choosing a control node, remember that any management system benefits from being run near the machines being managed. If you are using Ansible to manage machines in a cloud, consider using a machine inside that cloud as your control node. In most cases Ansible will perform better from a machine on the cloud than from a machine on the open Internet.

Ansible 2.11 will make Python 3.8 a soft dependency for the control node, but will function with the aforementioned requirements. Ansible 2.12 will require Python 3.8 or newer to function on the control node. Starting with Ansible 2.11, the project will only be packaged for Python 3.8 and newer.

Managed node requirements

Although you do not need a daemon on your managed nodes, you do need a way for Ansible to communicate with them. For most managed nodes, Ansible makes a connection over SSH and transfers modules using SFTP. If SSH works but SFTP is not available on some of your managed nodes, you can switch to SCP in ansible.cfg . For any machine or device that can run Python, you also need Python 2 (version 2.6 or later) or Python 3 (version 3.5 or later).

Please note that some modules have additional requirements that need to be satisfied on the ‘target’ machine (the managed node). These requirements should be listed in the module documentation.

If you have SELinux enabled on remote nodes, you will also want to install libselinux-python on them before using any copy/file/template related functions in Ansible. You can use the yum module or dnf module in Ansible to install this package on remote systems that do not have it.

By default, before the first Python module in a playbook runs on a host, Ansible attempts to discover a suitable Python interpreter on that host. You can override the discovery behavior by setting the ansible_python_interpreter inventory variable to a specific interpreter, and in other ways. See Interpreter Discovery for details.

Ansible’s raw module , and the script module , do not depend on a client side install of Python to run. Technically, you can use Ansible to install a compatible version of Python using the raw module , which then allows you to use everything else. For example, if you need to bootstrap Python 2 onto a RHEL-based system, you can install it as follows:

Selecting an Ansible artifact and version to install

Starting with version 2.10, Ansible distributes two artifacts: a community package called ansible and a minimalist language and runtime called ansible-core (called ansible-base in version 2.10). Choose the Ansible artifact and version that matches your particular needs.

Installing the Ansible community package

The ansible package includes the Ansible language and runtime plus a range of community curated Collections. It recreates and expands on the functionality that was included in Ansible 2.9.

You can choose any of the following ways to install the Ansible community package:

Install the latest release with your OS package manager (for Red Hat Enterprise Linux (TM), CentOS, Fedora, Debian, or Ubuntu).

Install with pip (the Python package manager).

Installing ansible-core 

Ansible also distributes a minimalist object called ansible-core (or ansible-base in version 2.10). It contains the Ansible language, runtime, and a short list of core modules and other plugins. You can build functionality on top of ansible-core by installing collections from Galaxy, Automation Hub, or any other source.

You can choose any of the following ways to install ansible-core :

Install ansible-core (version 2.11 and greater) or ansible-base (version 2.10) with pip .

Install ansible-core from source from the ansible/ansible GitHub repository to access the development ( devel ) version to develop or test the latest features.

You should only run ansible-core from devel if you are modifying ansible-core , or trying out features under development. This is a rapidly changing source of code and can become unstable at any point.

Ansible generally creates new releases twice a year. See Releases and maintenance for information on release timing and maintenance of older releases.

Installing and upgrading Ansible with pip 

Ansible can be installed on many systems with pip , the Python package manager.

Prerequisites: Installing pip 

If pip is not already available on your system, run the following commands to install it:

You may need to perform some additional configuration before you are able to run Ansible. See the Python documentation on installing to the user site for more information.

Installing Ansible with pip 

If you have Ansible 2.9 or older installed or Ansible 3, see Upgrading Ansible with pip .

Once pip is installed, you can install Ansible 1:

In order to use the paramiko connection plugin or modules that require paramiko , install the required module 2:

If you wish to install Ansible globally, run the following commands:

Running pip with sudo will make global changes to the system. Since pip does not coordinate with system package managers, it could make changes to your system that leaves it in an inconsistent or non-functioning state. This is particularly true for macOS. Installing with --user is recommended unless you understand fully the implications of modifying global files on the system.

Installing Ansible in a virtual environment with pip 

If you have Ansible 2.9 or older installed or Ansible 3, see Upgrading Ansible with pip .

Ansible can also be installed inside a new or existing virtualenv :

Upgrading Ansible with pip 

Upgrading from 2.9 or earlier to 2.10

Starting in version 2.10, Ansible is made of two packages. When you upgrade from version 2.9 and older to version 2.10 or later, you need to uninstall the old Ansible version (2.9 or earlier) before upgrading. If you do not uninstall the older version of Ansible, you will see the following message, and no change will be performed:

As explained by the message, to upgrade you must first remove the version of Ansible installed and then install it to the latest version.

Upgrading from Ansible 3 or ansible-core 2.10

ansible-base only exists for version 2.10 and in Ansible 3. In 2.11 and later, the package is called ansible-core . Before installing ansible-core or Ansible 4, you must uninstall ansible-base if you have installed Ansible 3 or ansible-base 2.10.

To upgrade to ansible-core :

To upgrade to Ansible 4:

Installing Ansible on specific operating systems

Follow these instructions to install the Ansible community package on a variety of operating systems.

Ansible by default manages machines over the SSH protocol.

Once Ansible is installed, it will not add a database, and there will be no daemons to start or keep running. You only need to install it on one machine (which could easily be a laptop) and it can manage an entire fleet of remote machines from that central point. When Ansible manages remote machines, it does not leave software installed or running on them, so there’s no real question about how to upgrade Ansible when moving to a new version.

What Version To Pick?¶

Because it runs so easily from source and does not require any installation of software on remote machines, many users will actually track the development version.

Ansible’s release cycles are usually about four months long. Due to this short release cycle, minor bugs will generally be fixed in the next release versus maintaining backports on the stable branch. Major bugs will still have maintenance releases when needed, though these are infrequent.

If you are wishing to run the latest released version of Ansible and you are running Red Hat Enterprise Linux (TM), CentOS, Fedora, Debian, or Ubuntu, we recommend using the OS package manager.

For other installation options, we recommend installing via “pip”, which is the Python package manager, though other options are also available.

If you wish to track the development release to use and test the latest features, we will share information about running from source. It’s not necessary to install the program to run from source.

Control Machine Requirements¶

Currently Ansible can be run from any machine with Python 2 (versions 2.6 or 2.7) or Python 3 (versions 3.5 and higher) installed (Windows isn’t supported for the control machine).

This includes Red Hat, Debian, CentOS, OS X, any of the BSDs, and so on.

Mac OS X by default is configured for a small number of file handles, so if you want to use 15 or more forks you’ll need to raise the ulimit with sudo launchctl limit maxfiles unlimited . This command can also fix any “Too many open files” error.

Please note that some modules and plugins have additional requirements. For modules these need to be satisfied on the ‘target’ machine and should be listed in the module specific docs.

Managed Node Requirements¶

On the managed nodes, you need a way to communicate, which is normally ssh. By default this uses sftp. If that’s not available, you can switch to scp in ansible.cfg . You also need Python 2 (version 2.6 or later) or Python 3 (version 3.5 or later).

If you have SELinux enabled on remote nodes, you will also want to install libselinux-python on them before using any copy/file/template related functions in Ansible. You can use the yum module or dnf module in Ansible to install this package on remote systems that do not have it.

By default, Ansible uses the python interpreter located at /usr/bin/python to run its modules. However, some Linux distributions may only have a Python 3 interpreter installed to /usr/bin/python3 by default. On those systems, you may see an error like:

you can either set the ansible_python_interpreter inventory variable (see Working with Inventory ) to point at your interpreter or you can install a Python 2 interpreter for modules to use. You will still need to set ansible_python_interpreter if the Python 2 interpreter is not installed to /usr/bin/python.

Ansible’s “raw” module (for executing commands in a quick and dirty way) and the script module don’t even need Python installed. So technically, you can use Ansible to install a compatible version of Python using the raw module , which then allows you to use everything else. For example, if you need to bootstrap Python 2 onto a RHEL-based system, you can install it via

Читайте также: