Ansible
ansible-playbook
ubuntu16.04

初心者のための「Ansibleを始める準備」

Ansibleコマンドをインストールする方法。

<もっと簡単なのがあったので追記。>
・pipコマンドの準備
apt install python3-pip
もしくは
apt install python-pip
・Ansibleのインストール。
pip3 install ansible

これでOK。

ーーーーーー<以下は古いやり方>ーーーーーー

OSの準備

環境(CentosとかUbuntu)の用意は適当に。
Targetに対してSSHしていくだけの環境なのでCPU1コアのMemory4GBとかでOKです。

公式ドキュメント

公式ドキュメントを見る。(Ansible Installation)
http://docs.ansible.com/ansible/latest/intro_installation.html

Linux系とUbuntu系(Debian?)は若干やり方がちがう。
個人的にはUbuntuがやりやすいと思う。
(LpicとかだとLinuxをベースに話が進んでいったりするけど細かいところでUbuntuのほうが親切だと思います。2017年現在)

Ubuntuの場合、
Latest Releases Via Apt (Ubuntu)を見る。

インストール

書いてある通りに実行するだけ。

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

インストールしてみる。

以下、実行ログ。

root@ajitama-repo-test:/root# sudo apt-get update
Hit:1 http://jp.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:3 http://jp.archive.ubuntu.com/ubuntu xenial-security InRelease
Reading package lists... Done
root@ajitama-repo-test:/root# sudo apt-get install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
software-properties-common is already the newest version (0.96.20.7).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@ajitama-repo-test:/root# sudo apt-add-repository ppa:ansible/ansible
 Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications— automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.

http://ansible.com/
 More info: https://launchpad.net/~ansible/+archive/ubuntu/ansible
Press [ENTER] to continue or ctrl-c to cancel adding it **(←ここでEnter★)**

gpg: keyring `/tmp/tmp0ycfwcsy/secring.gpg' created
gpg: keyring `/tmp/tmp0ycfwcsy/pubring.gpg' created
gpg: requesting key 7BB9C367 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp0ycfwcsy/trustdb.gpg: trustdb created
gpg: key 7BB9C367: public key "Launchpad PPA for Ansible, Inc." imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK
root@ajitama-repo-test:/root# sudo apt-get update
Hit:1 http://jp.archive.ubuntu.com/ubuntu xenial InRelease
Hit:2 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:3 http://jp.archive.ubuntu.com/ubuntu xenial-security InRelease
Get:4 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial InRelease [18.0 kB]
Get:5 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial/main amd64 Packages [540 B]
Get:6 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial/main i386 Packages [540 B]
Get:7 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial/main Translation-en [344 B]
Fetched 19.5 kB in 2s (8,840 B/s)
Reading package lists... Done
root@ajitama-repo-test:/root# sudo apt-get install ansible
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libyaml-0-2 python-cffi-backend python-crypto python-cryptography
  python-ecdsa python-enum34 python-httplib2 python-idna python-ipaddress
  python-jinja2 python-markupsafe python-paramiko python-pkg-resources
  python-pyasn1 python-setuptools python-six python-yaml sshpass
Suggested packages:
  python-crypto-dbg python-crypto-doc python-cryptography-doc
  python-cryptography-vectors python-enum34-doc python-jinja2-doc doc-base
  python-setuptools-doc
The following NEW packages will be installed:
  ansible libyaml-0-2 python-cffi-backend python-crypto python-cryptography
  python-ecdsa python-enum34 python-httplib2 python-idna python-ipaddress
  python-jinja2 python-markupsafe python-paramiko python-pkg-resources
  python-pyasn1 python-setuptools python-six python-yaml sshpass
0 upgraded, 19 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,059 kB of archives.
After this operation, 29.8 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 libyaml-0-2 amd64 0.1.6-3 [47.6 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-markupsafe amd64 0.23-2build2 [15.5 kB]
Get:3 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-jinja2 all 2.8-1 [109 kB]
Get:4 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-yaml amd64 3.11-3build1 [105 kB]
Get:5 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python-crypto amd64 2.6.1-6ubuntu0.16.04.2 [246 kB]
Get:6 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-six all 1.10.0-3 [10.9 kB]
Get:7 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-ecdsa all 0.13-2 [34.0 kB]
Get:8 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-paramiko all 1.16.0-1 [109 kB]
Get:9 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-httplib2 all 0.9.1+dfsg-1 [34.2 kB]
Get:10 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-pkg-resources all 20.7.0-1 [108 kB]
Get:11 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-setuptools all 20.7.0-1 [169 kB]
Get:12 http://jp.archive.ubuntu.com/ubuntu xenial/universe amd64 sshpass amd64 1.05-1 [10.5 kB]
Get:13 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-cffi-backend amd64 1.5.2-1ubuntu1 [58.1 kB]
Get:14 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-enum34 all 1.1.2-1 [35.8 kB]
Get:15 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-idna all 2.0-3 [35.1 kB]
Get:16 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-ipaddress all 1.0.16-1 [18.0 kB]
Get:17 http://jp.archive.ubuntu.com/ubuntu xenial/main amd64 python-pyasn1 all 0.1.9-1 [45.1 kB]
Get:18 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 python-cryptography amd64 1.2.3-1ubuntu0.1 [199 kB]
Get:19 http://ppa.launchpad.net/ansible/ansible/ubuntu xenial/main amd64 ansible all 2.4.1.0-1ppa~xenial [2,671 kB]
Fetched 4,059 kB in 2s (1,923 kB/s)
Selecting previously unselected package libyaml-0-2:amd64.
(Reading database ... 66332 files and directories currently installed.)
Preparing to unpack .../libyaml-0-2_0.1.6-3_amd64.deb ...
Unpacking libyaml-0-2:amd64 (0.1.6-3) ...
Selecting previously unselected package python-markupsafe.
Preparing to unpack .../python-markupsafe_0.23-2build2_amd64.deb ...
Unpacking python-markupsafe (0.23-2build2) ...
Selecting previously unselected package python-jinja2.
Preparing to unpack .../python-jinja2_2.8-1_all.deb ...
Unpacking python-jinja2 (2.8-1) ...
Selecting previously unselected package python-yaml.
Preparing to unpack .../python-yaml_3.11-3build1_amd64.deb ...
Unpacking python-yaml (3.11-3build1) ...
Selecting previously unselected package python-crypto.
Preparing to unpack .../python-crypto_2.6.1-6ubuntu0.16.04.2_amd64.deb ...
Unpacking python-crypto (2.6.1-6ubuntu0.16.04.2) ...
Selecting previously unselected package python-six.
Preparing to unpack .../python-six_1.10.0-3_all.deb ...
Unpacking python-six (1.10.0-3) ...
Selecting previously unselected package python-ecdsa.
Preparing to unpack .../python-ecdsa_0.13-2_all.deb ...
Unpacking python-ecdsa (0.13-2) ...
Selecting previously unselected package python-paramiko.
Preparing to unpack .../python-paramiko_1.16.0-1_all.deb ...
Unpacking python-paramiko (1.16.0-1) ...
Selecting previously unselected package python-httplib2.
Preparing to unpack .../python-httplib2_0.9.1+dfsg-1_all.deb ...
Unpacking python-httplib2 (0.9.1+dfsg-1) ...
Selecting previously unselected package python-pkg-resources.
Preparing to unpack .../python-pkg-resources_20.7.0-1_all.deb ...
Unpacking python-pkg-resources (20.7.0-1) ...
Selecting previously unselected package python-setuptools.
Preparing to unpack .../python-setuptools_20.7.0-1_all.deb ...
Unpacking python-setuptools (20.7.0-1) ...
Selecting previously unselected package sshpass.
Preparing to unpack .../sshpass_1.05-1_amd64.deb ...
Unpacking sshpass (1.05-1) ...
Selecting previously unselected package python-cffi-backend.
Preparing to unpack .../python-cffi-backend_1.5.2-1ubuntu1_amd64.deb ...
Unpacking python-cffi-backend (1.5.2-1ubuntu1) ...
Selecting previously unselected package python-enum34.
Preparing to unpack .../python-enum34_1.1.2-1_all.deb ...
Unpacking python-enum34 (1.1.2-1) ...
Selecting previously unselected package python-idna.
Preparing to unpack .../python-idna_2.0-3_all.deb ...
Unpacking python-idna (2.0-3) ...
Selecting previously unselected package python-ipaddress.
Preparing to unpack .../python-ipaddress_1.0.16-1_all.deb ...
Unpacking python-ipaddress (1.0.16-1) ...
Selecting previously unselected package python-pyasn1.
Preparing to unpack .../python-pyasn1_0.1.9-1_all.deb ...
Unpacking python-pyasn1 (0.1.9-1) ...
Selecting previously unselected package python-cryptography.
Preparing to unpack .../python-cryptography_1.2.3-1ubuntu0.1_amd64.deb ...
Unpacking python-cryptography (1.2.3-1ubuntu0.1) ...
Selecting previously unselected package ansible.
Preparing to unpack .../ansible_2.4.1.0-1ppa~xenial_all.deb ...
Unpacking ansible (2.4.1.0-1ppa~xenial) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libyaml-0-2:amd64 (0.1.6-3) ...
Setting up python-markupsafe (0.23-2build2) ...
Setting up python-jinja2 (2.8-1) ...
Setting up python-yaml (3.11-3build1) ...
Setting up python-crypto (2.6.1-6ubuntu0.16.04.2) ...
Setting up python-six (1.10.0-3) ...
Setting up python-ecdsa (0.13-2) ...
Setting up python-paramiko (1.16.0-1) ...
Setting up python-httplib2 (0.9.1+dfsg-1) ...
Setting up python-pkg-resources (20.7.0-1) ...
Setting up python-setuptools (20.7.0-1) ...
Setting up sshpass (1.05-1) ...
Setting up python-cffi-backend (1.5.2-1ubuntu1) ...
Setting up python-enum34 (1.1.2-1) ...
Setting up python-idna (2.0-3) ...
Setting up python-ipaddress (1.0.16-1) ...
Setting up python-pyasn1 (0.1.9-1) ...
Setting up python-cryptography (1.2.3-1ubuntu0.1) ...
Setting up ansible (2.4.1.0-1ppa~xenial) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
root@ajitama-repo-test:/root#

ansibleのVersion確認

root@ajitama-repo-test:/root# ansible --version
ansible 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ajitama/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
root@ajitama-repo-test:/root# ansible-playbook --version
ansible-playbook 2.4.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ajitama/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]