LoginSignup
5
2

More than 1 year has passed since last update.

Ansible 「で」 python 「を」 リモートーサーバーにインストールする方法

Last updated at Posted at 2018-07-15

リモートサーバーにpythonが必要なのに、python自体をどうやってインストールするのか。

答え

raw モジュール / script モジュールはリモートサーバーに python を必要としない。これを利用するのが良さそう。

Ansible’s “raw” module (for executing commands in a quick and dirty way) and the script module don’t even need Python installed.
...
ansible myhost --sudo -m raw -a "yum install -y python2"

Installation Guide — Ansible Documentation

モジュールが利用できる確認

ここでは単に ls が叩けることを確認。

shell モジュールを実行しようとして怒られる例。

$ ansible -i inventory.txt example_group -m 'command' -a 'ls -la'

localhost | FAILED! => {
    "changed": false,
    "module_stderr": "Shared connection to ******* closed.\r\n",
    "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",
    "msg": "MODULE FAILURE",
    "rc": 127
}

raw モジュールでは怒られない。

$ ansible -i inventory.txt example_group -m 'raw' -a 'ls -la /'

localhost | SUCCESS | rc=0 >>
total 24
drwx------ 1 root root 4096 Jul 15 01:19 .
drwxr-xr-x 1 root root 4096 Jul 15 01:19 ..
drwx------ 3 root root 4096 Jul 15 01:19 .ansible
-rw-r--r-- 1 root root 3106 Oct 22  2015 .bashrc
drwx------ 2 root root 4096 Jul 15 01:19 .cache
-rw-r--r-- 1 root root  148 Aug 17  2015 .profile
Shared connection to localhost closed.

環境

  • ansible 2.6.1

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

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