0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ansibleをソースからインストールする

Posted at

はじめに

CentOSのyumリポジトリだとバージョンが若干古かったので、
ソースからビルド、インストールすることにしました。
Ansible 2.8.0 をソースからインストールする手順です。

Ansible公式のインストール手順を元に書いてあることをやっていきます。

環境

CentOS 7

$ uname -a
Linux manager 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

手順

Ansible_stable-2.8
$ git clone -b stable-2.8 https://github.com/ansible/ansible.git
$ cd ansible
$ source ./hacking/env-setup
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py --user
$ pip install --user -r ./requirements.txt 
$ git pull --rebase
おそらく各言語対応
$ LANG=en_US git submodule update --init --recursive
ホスト登録({host}=IPアドレスまたはホスト名)
$ echo {host} > ~/ansible_hosts
$ export ANSIBLE_INVENTORY=~/ansible_hosts
動作確認
$ ansible all -m 'ping' --ask-pass

※{host} はlocalhostを指定した場合、sshで接続できませんでした。

参考

これだけでしたが色々と調べることになってしまいました。
CentOSのバージョン確認方法
ブランチやタグを指定してgit cloneできることを知った

おまけ

今回の手順をVagrantfileにもしました。

Vagrantfile
Vagrant.configure("2") do |config|
  # manager-VM
  config.vm.define "manager" do |manager|
    manager.vm.box = "centos/7"
    manager.vm.hostname = "manager"
    manager.vm.network "private_network", ip: "192.168.96.5"
    manager.vm.synced_folder './server', '/vagrant', :mount_options => ['dmode=775', 'fmode=664']

    manager.vm.provider "virtualbox" do |vb|
      vb.memory = 1024
      vb.cpus = 2
    end
    
    manager.vm.provision "shell", inline: <<-SHELL
      # IPv6 disable
      cp /vagrant/disable_ipv6.conf /etc/sysctl.d/disable_ipv6.conf
      sysctl -p /etc/sysctl.d/disable_ipv6.conf

      # update package
      # yum update -y
      # yum install -y ansible
      yum install -y PyYAML libyaml \
                     python-babel python-backports \
                     python-backports-ssl_match_hostname \
                     python-cffi       python-enum34 \
                     python-httplib2   python-idna   \
                     python-ipaddress  python-jinja2 \
                     python-markupsafe python-paramiko \
                     python-passlib    python-ply      \
                     python-pycparser  python-setuptools \
                     python-six        python2-cryptography \
                     python2-jmespath  python2-pyasn1       \
                     sshpass           \
                     git

    SHELL

    manager.vm.provision "shell", name: "Registory ssh-key", privileged: false, inline: <<-SHELL
      # registry ssh-key
      ssh-keygen -N "" -t ed25519 -f ~/.ssh/id_ed25519

      # registry known_hosts
      ssh-keyscan -H manager >> ~/.ssh/known_hosts

      # registry authorized_keys
      cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
      # ssh-copy-id vagrant@manager

    SHELL

    manager.vm.provision "shell", name: "Install Ansible", privileged: false, inline: <<-SHELL
      # install Ansible stable-2.8
      git clone -b stable-2.8 https://github.com/ansible/ansible.git ~/ansible
      cd ~/ansible
      source ./hacking/env-setup
      curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
      python ~/ansible/get-pip.py --user
      pip install --user -r ~/ansible/requirements.txt
      git pull --rebase

      echo manager > ~/ansible_hosts
      echo "export ANSIBLE_INVENTORY=~/ansible_hosts" >> ~/.bashrc
      echo "LANG=en_US . ~/ansible/hacking/env-setup" >> ~/.bashrc
  
      # copy playbook
      cp -pR /vagrant/playbook ~/
    SHELL
  end
end

※仮想マシンはlibvirtを使用しています。VirtualBoxを使用している方は読み替えお願いします。
※ゲストOSはCentOS7です。
※Ansibleのインストール以外に、IPv6の無効化、ssh-keyの生成(ed25519)、もやってます。
※Ansibleについて、日本語非対応みたいです。
(LANG=ja_JP.UTF-8の場合、エラーがでました。

can't set the locale; make sure $LC_* and $LANG are correct
```)
※ansibleのセットアップ中に警告(```manager: warning: no files found matching 'SYMLINK_CACHE.json'```)が出ましたが、どうやらテストで使用するファイルの様ですので、無視しております。
0
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?