从源代码安装Ansible
首先
由于CentOS的yum仓库中的版本稍旧,我决定从源代码编译并安装。下面是从源代码安装Ansible 2.8.0的步骤。
我将按照Ansible公式安装指南进行操作。
环境
CentOS 7: 中文: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)
步骤
$ 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
$ echo {host} > ~/ansible_hosts
$ export ANSIBLE_INVENTORY=~/ansible_hosts
$ ansible all -m 'ping' --ask-pass
※如果主机指定为localhost,则无法通过ssh连接。
请参考
这只是一小部分,结果却让我不得不进行各种各样的调查。
我了解到可以通过指定分支或标签来使用git clone。
附赠
我在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的用户请替换。
※客户操作系统为CentOS7。
※除了安装Ansible之外,还进行了禁用IPv6、生成ssh-key(ed25519)的操作。
※关于Ansible,似乎不支持日语。
(当LANG=ja_JP.UTF-8时,出现错误。
manpath: can’t set the locale; make sure $LC_* and $LANG are correct
)
※安装ansible过程中出现警告(manager: warning: no files found matching ‘SYMLINK_CACHE.json’),看起来像是用于测试的文件,所以忽略它。