LoginSignup
2
0

More than 3 years have passed since last update.

IBM Cloud Virtual Server for Classic で Red Hat Enterprise Linux 8 に Ansible をインストールする

Posted at

Red Hat Enterprise Linux 8 確認

IBM Cloud Virtual Server for Classic で Red Hat Enterprise Linux 8 が 2020年7月26日にリリースされていました。

https://cloud.ibm.com/gen1/infrastructure/image-templates
Kobito.ur06oa.png

プロビジョニングしたところ、上記の通り、バージョンは 8.2 だと確認できました。


[root@khayama-control ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.2 (Ootpa)

Python がない

8.x ではデフォルトで python コマンドが実行できない状態なのでインストールします。


[root@khayama-control ~]# python
-bash: python: コマンドが見つかりません
[root@khayama-control ~]# python2
-bash: python2: コマンドが見つかりません
[root@khayama-control ~]# python3
-bash: python3: コマンドが見つかりません

Python インストール

yum の代わりに dnf を使って python をインストールします。


dnf install python38 -y
python3 -V

パッケージ管理システムがDNFをベースとしたYum v4に変更されました。
yumコマンドはdnfコマンドに変更となります。今のところyumコマンドも後方互換として残されていますが、いずれは廃止となる予定です。
パッケージ管理に自前の運用スクリプトを使用している場合は、今後を見据えてdnfコマンドに対応させたほうがよいでしょう。

参考 : 個人的に気になったRHEL 8の変更点 | 電算星組

pip インストール

今後はこのように python3 -m pip と実行するのが推奨のようです。


python3 -m pip install --upgrade pip
python3 -m pip --version

Ansible インストール

pip を使用した Ansible のインストールを行います。


python3 -m pip install ansible

最新版が導入できました。
リリースノートは Release and maintenance から確認できます。


[root@khayama-control ~]# ansible --version
ansible 2.9.13
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.0 (default, Mar  9 2020, 18:02:46) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]

SSH 鍵の登録

引き続き、 Controle Node にて SSH 鍵を作成し、 Target Node に登録します。


ssh-keygen

ssh-copy-id -i $HOME/.ssh/id_rsa.pub localhost

ssh-copy-id -i $HOME/.ssh/id_rsa.pub root@10.192.109.187 # target node ip address

Ansible トレイルマップ MOUNT YAML STEP3
Kobito.UtXF6S.png

ping 確認

localhost への ping 実行を確認できます。


mkdir /etc/ansible/test1
cd /etc/ansible/test1

cat <<EOF > inventory.ini
[test_servers]
localhost
EOF

[root@khayama-control test1]# ansible -i inventory.ini test_servers -m ping
localhost | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

ディレクトリ作成 & ファイルコピー確認

Target Node へのディレクトリ作成 & ファイルコピーを確認できます。


mkdir /etc/ansible/test2
cd /etc/ansible/test2

cat <<EOF > inventory.ini
[test_servers]
10.192.109.187
EOF

cat <<EOF > playbook.yml
---
- hosts: test_servers
  tasks:
  - name: create directory
    file:
       path: /root/tmp
       state: directory 
       owner: root
       mode: 0755

  - name: copy file
    copy:
       src: /etc/hosts
       dest: /root/tmp/hosts
       owner: root
       mode: 0644
EOF

[root@khayama-control test2]# ansible-playbook -i inventory.ini playbook.yml 

PLAY [test_servers] **********************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************
ok: [10.192.109.187]

TASK [create directory] ******************************************************************************************************************************************************************************
changed: [10.192.109.187]

TASK [copy file] *************************************************************************************************************************************************************************************
changed: [10.192.109.187]

PLAY RECAP *******************************************************************************************************************************************************************************************
10.192.109.187             : ok=3    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

さいごに

これで IBM Cloud の Red Hat Enterprise Linux 8 で Ansible を使う準備が整いました。
IBM Cloud でも Ansible を使ってみてください。

参考

2
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
2
0