0
0

More than 3 years have passed since last update.

CentOS8のAnsible管理サーバ設定

Last updated at Posted at 2020-03-27

pip3 のインストール

管理者権限でpip3をインストールする。


[root@mng053 ~]# dnf install python3 python3-pip
Last metadata expiration check: 0:03:06 ago on Fri 27 Mar 2020 10:47:42 PM JST.

Dependencies resolved.

 Package            Arch   Version                              Repo       Size

Installing:
 python3-pip        noarch 9.0.3-15.el8                         AppStream  19 k
 python36           x86_64 3.6.8-2.module_el8.1.0+245+c39af44f  AppStream  19 k
Installing dependencies:
 python3-setuptools noarch 39.2.0-5.el8                         BaseOS    162 k
Enabling module streams:
 python36                  3.6

Transaction Summary

Install  3 Packages
(以下略)

python3(36)は別の都合で明示的に入れています。
指定しなくても依存関係で入る見たいですが・・・

作業をしたら、必ず確認をしましょう。


[root@mng053 ~]# dnf list | egrep "python36|python3-pip"
python3-pip.noarch                                   9.0.3-15.el8                                      @AppStream
python3-pip-wheel.noarch                             9.0.3-15.el8                                      @BaseOS
python36.x86_64                                      3.6.8-2.module_el8.1.0+245+c39af44f               @AppStream
python36-debug.x86_64                                3.6.8-2.module_el8.1.0+245+c39af44f               AppStream
python36-devel.x86_64                                3.6.8-2.module_el8.1.0+245+c39af44f               AppStream
python36-rpm-macros.noarch                           3.6.8-2.module_el8.1.0+245+c39af44f               AppStream

Ansibleのインストール

前提作業

まずはAnsible用ユーザを作成します。


[root@mng053 ~]# passwd ansible
Changing password for user ansible.
New password:                           ⇒パスワードを入れてEnter
Retype new password:                    ⇒同じパスワードを入れてEnter

ユーザの存在確認


[root@mng053 ~]# id ansible
uid=1001(ansible) gid=1001(ansible) groups=1001(ansible)

本作業

Ansibleはpip3でインストールします。


[ansible@mng053 ~]$ pip3 install ansible --user
Collecting ansible
  Downloading https://files.pythonhosted.org/packages/ae/b7/c717363f767f7a ・・・

(中略)

Installing collected packages: MarkupSafe, jinja2, pycparser, cffi, cryptography, ansible
  Running setup.py install for ansible ... done
Successfully installed MarkupSafe-1.1.1 ansible-2.9.6 cffi-1.14.0 cryptography-2.8 jinja2-2.11.1 pycparser-2.20

pip3はPythonのパッケージインストールツールです。
--userのオプションは~/.localにインストールするオプションです。

で、やっぱり確認


[ansible@mng053 ~]$ ansible --version
ansible 2.9.6
  config file = None
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ansible/.local/lib/python3.6/site-packages/ansible
  executable location = /home/ansible/.local/bin/ansible
  python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]

"ansible python module location" の行で、ホームディレクトリ下層のpython3.6ディレクトリの中に
インストールされていることがわかりますね。

SSH鍵の作成

ssh-keygenコマンドで鍵を生成します。
ansible用ユーザで作業します。


[ansible@mng053 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ansible/.ssh/id_rsa): 
Created directory '/home/ansible/.ssh'.
Enter passphrase (empty for no passphrase):     ⇒Enterを押す
Enter same passphrase again:                    ⇒Enterを押す
Your identification has been saved in /home/ansible/.ssh/id_rsa.
Your public key has been saved in /home/ansible/.ssh/id_rsa.pub.
The key fingerprint is:
(以下略)

で、くどいですが確認


[ansible@mng053 ~]$ ls -l .ssh
total 8
-rw-------. 1 ansible ansible 2610 Mar 27 23:01 id_rsa
-rw-r--r--. 1 ansible ansible  580 Mar 27 23:01 id_rsa.pub

秘密鍵と公開鍵のペアが作成されています。
~.pubのほうが公開鍵なのでこれをAnsibleでセットアップしたいコンピュータに配置します。

インベントリ用のディレクトリ作成

ansibleのインベントリ等は/etc/ansibleに格納するのが標準とこのと。
ユーザのホームディレクトリにモノを作って/etcに情報格納するのに違和感はありつつも、
よくわからないので従ってみることにします。


[root@mng053 ~]# mkdir /etc/ansible
[root@mng053 ~]# chown ansible:ansible /etc/ansible

ディレクトリの確認


[root@mng053 ~]# ls -ld /etc/ansible
drwxr-xr-x. 2 ansible ansible 6 Mar 28 09:27 /etc/ansible
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0