Как установить ansible на mac os
Перейти к содержимому

Как установить ansible на mac os

  • автор:

Как установить Ansible

Ansible это система управления конфигурациями, которая используется для автоматизации настройки инфраструктуры. Эта статья является кратким руководством по её установке.

Предварительные требования

Для установки Ansible потребуется наличие Python версии не ниже 3.5 и pip.

Чтобы проверить версию Python, выполните команду python —version или python3 —version . Если нужной версии Python нет, установите её с официального сайта.

MacOS/Linux

Для данных операционных систем предпочтительным является метод установки через pip.

Для этого надо запустить следующую команду:

pip install ansible

Или если нет pip, но есть pip3:

pip3 install ansible

Чтобы проверить, что всё успешно установилось, выполните команду

ansible —version

Если всё сделано верно, команда должна вывести установленную версию Ansible:

Windows

Установку Ansible на Windows мы рекомендуем выполнять через WSL. Вам необходимо иметь Windows 10 для работы с WSL. Если вы не знакомы с этой технологией, то рекомендуем почитать про неё подробнее здесь. Инструкция по установке WSL 2 от Microsoft вы найдёте здесь.

В качестве дистрибутива для WSL мы рекомендуем использовать Ubuntu 20.04 LTS. Его можно загрузить из официального магазина приложений.

После установки и настройки выбранного вами дистрибутива, установка Ansible ничем не отличается от его установки на Linux:

pip install ansible # or pip3 ansible —version # for installation verifying

If you like this article, share a link with your friends

Read more

We talk about interesting technologies and share our experience of using them.

Как установить Ansible на Apple MacOS X с помощью командной строки

Как установить программное обеспечение Ansible для автоматизации приложений и IT-инфраструктуры с моего Apple Macbook pro, работающего на MacOS X?

Ansible — это самое простое и простое в использовании программное обеспечение для автоматизации приложений и IT-инфраструктуры. Вы можете использовать Ansible для развертывания приложений, управления конфигурацией, и для реализации множество задач, связанных с системным администрированием.

Установите Ansible на MacOS с помощью команды brew

Откройте приложение терминала и введите следующую команду:

$ brew install ansible

Примеры возможных выводов данных:

Как установить Ansible на Apple MacOS X с помощью командной строки

Теперь ваш Macbook pro действует, как главный узел или система управления.

Создание файла инвентаризации хостов

Ansible должен знать, к каким сервера подключиться, и затем управлять этими блоками. Вам нужно определить или создать перечень файлов хоста Ansible. Файл содержит список, параметры и группы для ваших серверов. Его местоположение по умолчанию — /usr/local/etc/ansible/hosts в MacOS X. Вы можете отредактировать файл /usr/local/etc/ansible/hosts или создать файл ~ / hosts :

$ vi ~/hosts

Вот пример моего файла:

box1 192.168.2.15

Сохраните изменения и закройте файл. Убедитесь, что вы установили ключи ssh в серверах box1 и 192.168.2.15. Если у вас нет ключа ssh на MacOS X, сгенерируйте ключ ssh на главном узле (MacOS X):

$ ssh-keygen -t rsa -C "OS X laptop ssh key"

Установите ssh ключ:

$ ssh-copy-id -i ~/.ssh/id_rsa.pub box1 $ ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.2.15
$ ansible all --inventory-file=~/hosts -m ping

Примеры возможных выводов данных:

192.168.2.15 | SUCCESS => < "changed": false, "ping": "pong" >box1 | SUCCESS =>

Вы можете установить ANSIBLE_HOSTS для определения вашего файла ~ / hosts :

$ export ANSIBLE_HOSTS=~/hosts $ echo 'export ANSIBLE_HOSTS=~/hosts' >> ~/.bashrc $ ansible all -m ping ## let us run uptime command all hosts ## $ ansible all -a 'uptime'

Примеры возможных выводов данных:

192.168.2.15 | SUCCESS | rc=0 >> 01:20:36 up 10:06, 2 users, load average: 0.47, 0.46, 0.20 box1 | SUCCESS | rc=0 >> 19:50:41 up 58 min, 1 user, load average: 0.00, 0.00, 0.00

Что дальше?

Чтобы управлять вашим сервером, вам нужны Ansible’s playbooks. Ознакомьтесь со следующими ресурсами для получения большей информации: Документация Ansible.

  • Установка и настройка Apache, PHP, MySQL, phpMyAdmin на Linux (LAMP)
  • Установка и настройка сервера Apache, PHP, MySQL, phpMyAdmin на Windows 10
  • Установка Adobe Photoshop CS6 на Linux (очень простой способ)

Оставить ответ Отменить ответ

�� С 20 по 22 апреля пройдут незабываемые битвы среди кибер-гладиаторов в мире информационной безопасности!

Открыта регистрация команд по ссылке .

Install Ansible on Mac OSX

If you already have Homebrew installed, then it is as simple as:

> brew install ansible 

If you prefer to use Python and pip for the install, then read on.

Native Python Install — Summary:

Ansible uses Python and fortunately Python is already installed on modern versions of OSX.

  • Install Xcode
  • sudo easy_install pip
  • sudo pip install ansible —quiet

Then, if you would like to update Ansible later, just do:

  • sudo pip install ansible —upgrade

Native Python Install — Full explanation:

Ensure Xcode is installed first

Some of Ansible’s dependencies need to be compiled, so you’ll need the developer tools that come with Xcode.

You can check if you already have the developer tools by running this:

> pkgutil --pkg-info=com.apple.pkg.CLTools_Executables 

(note: Before OSX Mavericks, the package to check for was «com.apple.pkg.DeveloperToolsCLI»)

If the tools are not installed, you will see this output:

> pkgutil --pkg-info=com.apple.pkg.CLTools_Executables No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'. 

In that case, download and install Xcode from here.

If the tools are installed, you should see output similar to this:

> pkgutil --pkg-info=com.apple.pkg.CLTools_Executables package-id: com.apple.pkg.CLTools_Executables version: 5.1.0.0.1.1396320587 volume: / location: / install-time: 1397415256 groups: com.apple.FindSystemFiles.pkg-group com.apple.DevToolsBoth.pkg-group com.apple.DevToolsNonRelocatableShared.pkg-group 

Install pip

pip is Python’s package manager. It isn’t installed on OSX by default, but you can use Python’s other package manager easy_install to install it:

> sudo easy_install pip Password: Searching for pip Reading http://pypi.python.org/simple/pip/ Best match: pip 1.4.1 Downloading https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz#md5=6afbb46aeb48abac658d4df742bff714 Processing pip-1.4.1.tar.gz Running pip-1.4.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-hVr8Pt/pip-1.4.1/egg-dist-tmp-BY70iY warning: no files found matching '*.html' under directory 'docs' warning: no previously-included files matching '*.rst' found under directory 'docs/_build' no previously-included directories found matching 'docs/_build/_sources' Adding pip 1.4.1 to easy-install.pth file Installing pip script to /usr/local/bin Installing pip-2.7 script to /usr/local/bin Installed /Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg Processing dependencies for pip Finished processing dependencies for pip 

Install Ansible

> sudo pip install ansible . lots of output and warnings you can ignore. Successfully installed ansible paramiko jinja2 PyYAML pycrypto ecdsa markupsafe Cleaning up. 

Upgrade Ansible

When a new release of Ansible comes out, you can easily upgrade to the new version like this:

> sudo pip install ansible --upgrade 

Installing Ansible

Ansible is an agentless automation tool that you install on a single host (referred to as the control node).

From the control node, Ansible can manage an entire fleet of machines and other devices (referred to as managed nodes) remotely with SSH, Powershell remoting, and numerous other transports, all from a simple command-line interface with no databases or daemons required.

Control node requirements

For your control node (the machine that runs Ansible), you can use nearly any UNIX-like machine with Python 3.9 or newer installed. This includes Red Hat, Debian, Ubuntu, macOS, BSDs, and Windows under a Windows Subsystem for Linux (WSL) distribution. Windows without WSL is not natively supported as a control node; see Matt Davis’ blog post for more information.

Managed node requirements

The managed node (the machine that Ansible is managing) does not require Ansible to be installed, but requires Python 2.7, or Python 3.5 — 3.11 to run Ansible-generated Python code. The managed node also needs a user account that can connect through SSH to the node with an interactive POSIX shell.

There can be exceptions in module requirements. For example, network modules do not require Python on the managed device. See documentation for the modules you use.

Node requirement summary

You can find details about control and managed node requirements for each Ansible version in the ansible-core control node Python support .

Selecting an Ansible package and version to install

Ansible’s community packages are distributed in two ways:

  • ansible-core : a minimalist language and runtime package containing a set of Ansible.Builtin .
  • ansible : a much larger “batteries included” package, which adds a community-curated selection of Ansible Collections for automating a wide variety of devices.

Choose the package that fits your needs. The following instructions use ansible as a package name, but you can substitute ansible-core if you prefer to start with the minimal package and separately install only the Ansible Collections you require.

The ansible or ansible-core packages may be available in your operating systems package manager, and you are free to install these packages with your preferred method. For more information, see the Installing Ansible on specific operating systems guide. These installation instructions only cover the officially supported means of installing the python packages with pip .

See the Ansible package release status table for the ansible-core version included in the package.

Installing and upgrading Ansible with pipx

On some systems, it may not be possible to install Ansible with pip , due to decisions made by the operating system developers. In such cases, pipx is a widely available alternative.

These instructions will not go over the steps to install pipx ; if those instructions are needed, please continue to the pipx installation instructions for more information.

Installing Ansible

Use pipx in your environment to install the full Ansible package:

$ pipx install --include-deps ansible

You can install the minimal ansible-core package:

$ pipx install ansible-core

Alternately, you can install a specific version of ansible-core :

$ pipx install ansible-core==2.12.3

Upgrading Ansible

To upgrade an existing Ansible installation to the latest released version:

$ pipx upgrade --include-injected ansible

Installing Extra Python Dependencies

To install additional python dependencies that may be needed, with the example of installing the argcomplete python package as described below:

$ pipx inject ansible argcomplete

Include the —include-apps option to make apps in the additional python dependency available on your PATH. This allows you to execute commands for those apps from the shell.

$ pipx inject --include-apps ansible argcomplete

Installing and upgrading Ansible with pip

Locating Python

Locate and remember the path to the Python interpreter you wish to use to run Ansible. The following instructions refer to this Python as python3 . For example, if you have determined that you want the Python at /usr/bin/python3.9 to be the one that you will install Ansible under, specify that instead of python3 .

Ensuring pip is available

To verify whether pip is already installed for your preferred Python:

$ python3 -m pip -V

If all is well, you should see something like the following:

$ python3 -m pip -V pip 21.0.1 from /usr/lib/python3.9/site-packages/pip (python 3.9) 

If so, pip is available, and you can move on to the next step .

If you see an error like No module named pip , you will need to install pip under your chosen Python interpreter before proceeding. This may mean installing an additional OS package (for example, python3-pip ), or installing the latest pip directly from the Python Packaging Authority by running the following:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py $ python3 get-pip.py --user

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

Use pip in your selected Python environment to install the full Ansible package for the current user:

$ python3 -m pip install --user ansible

You can install the minimal ansible-core package for the current user:

$ python3 -m pip install --user ansible-core

Alternately, you can install a specific version of ansible-core :

$ python3 -m pip install --user ansible-core==2.12.3

Upgrading Ansible

To upgrade an existing Ansible installation in this Python environment to the latest released version, simply add —upgrade to the command above:

$ python3 -m pip install --upgrade --user ansible

Installing for development

If you are testing new features, fixing bugs, or otherwise working with the development team on changes to the core code, you can install and run the source from GitHub.

You should only install and run the devel branch 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.

For more information on getting involved in the Ansible project, see the Ansible Community Guide .

For more information on creating Ansible modules and Collections, see the Developer Guide .

Installing devel from GitHub with pip 

You can install the devel branch of ansible-core directly from GitHub with pip :

$ python3 -m pip install --user https://github.com/ansible/ansible/archive/devel.tar.gz

You can replace devel in the URL mentioned above, with any other branch or tag on GitHub to install older versions of Ansible, tagged alpha or beta versions, and release candidates.

Running the devel branch from a clone

ansible-core is easy to run from source. You do not need root permissions to use it and there is no software to actually install. No daemons or database setup are required.

    Clone the ansible-core repository

$ git clone https://github.com/ansible/ansible.git $ cd ./ansible
    Using Bash
$ source ./hacking/env-setup
$ source ./hacking/env-setup.fish
$ source ./hacking/env-setup -q
$ python3 -m pip install --user -r ./requirements.txt
$ git pull --rebase

Confirming your installation

You can test that Ansible is installed correctly by checking the version:

$ ansible --version

The version displayed by this command is for the associated ansible-core package that has been installed.

To check the version of the ansible package that has been installed:

$ ansible-community --version

Adding Ansible command shell completion

You can add shell completion of the Ansible command line utilities by installing an optional dependency called argcomplete . It supports bash, and has limited support for zsh and tcsh.

For more information about installation and configuration, see the argcomplete documentation.

Installing argcomplete 

If you chose the pipx installation instructions:

$ pipx inject --include-apps ansible argcomplete

If you chose the pip installation instructions:

$ python3 -m pip install --user argcomplete

Configuring argcomplete 

There are 2 ways to configure argcomplete to allow shell completion of the Ansible command line utilities: globally or per command.

Global configuration

Global completion requires bash 4.2.

$ activate-global-python-argcomplete --user

This will write a bash completion file to a user location. Use —dest to change the location or sudo to set up the completion globally.

Per command configuration

If you do not have bash 4.2, you must register each script independently.

$ eval $(register-python-argcomplete ansible) $ eval $(register-python-argcomplete ansible-config) $ eval $(register-python-argcomplete ansible-console) $ eval $(register-python-argcomplete ansible-doc) $ eval $(register-python-argcomplete ansible-galaxy) $ eval $(register-python-argcomplete ansible-inventory) $ eval $(register-python-argcomplete ansible-playbook) $ eval $(register-python-argcomplete ansible-pull) $ eval $(register-python-argcomplete ansible-vault) 

You should place the above commands into your shells profile file such as ~/.profile or ~/.bash_profile .

Using argcomplete with zsh or tcsh

Examples of basic commands

Learning ansible’s configuration management language

Ansible Installation related to FAQs

Questions? Help? Ideas? Stop by the list on Google Groups

How to join Ansible chat channels

© Copyright Ansible project contributors. Last updated on Nov 16, 2023.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *