Jenkins + Ansible + Gitlab(二)

Ansible与Chef,Saltstack的不同

Chef
       Ruby语言编写,C/S架构,配置需要Git依赖
       Recipe脚本编写规范,需要编程经验
Saltstack
      Python语言编写,C/S架构,模块化配置管理
      YAML脚本编写规范,适合大规模集群部署
Ansible
      Python语言编写,无Client,模块化配置管理
      Playbook脚本编写规范,易于上手,适合中小规模快速部署
 


Ansible配合virtualenv安装配置

机器的防火墙和selinux要关闭...

ansible两种安装模式:

1.预先安装Python3.6版本

  • [root@ansible ~]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
  • [root@ansible ~]# tar xf Python-3.7.2.tar.xz 
  • [root@ansible Python-3.7.2]# 
    [root@ansible Python-3.7.2]# ./configure  \
    > --prefix=/usr/local \
    > --with-ensurepip=install \
    > --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
  • [root@ansible Python-3.7.2]# make && make altinstall

2.安装virtualenv

pip加速:https://blog.csdn.net/qq_33317586/article/details/84205769

  • [root@ansible Python-3.7.2]# which pip3.7
    /usr/local/bin/pip3.7
    [root@ansible Python-3.7.2]# ln -s /usr/local/bin/pip3.7 /usr/local/bin/pip
    [root@ansible Python-3.7.2]# pip install virtualenv

3.创建Ansible账户并安装

  • [root@ansible Python-3.7.2]# useradd deploy
  • [root@ansible Python-3.7.2]# su - deploy
  • [deploy@ansible ~]$ virtualenv -p /usr/local/bin/python3.7 .py3-a2.7.8-env (创建python3.7virtualenv实例)

4.git源代码安装ansible2.6

  • [deploy@ansible ~]$ cd /home/deploy/.py3-a2.7.8-env/
  • [deploy@ansible .py3-a2.7.8-env]$ which git
    /bin/git
  • [deploy@ansible ~]$ git clone https://github.com/ansible/ansible.git

5.加载python3.6 virtualenv环境

  • [deploy@ansible ~]$ source /home/deploy/.py3-a2.7.8-env/bin/activate
    (.py3-a2.7.8-env) [deploy@ansible ~]$

6.安装ansible依赖包

  • (.py3-a2.7.8-env) [deploy@ansible ~]$ pip install paramiko PyYAML jinja2

7.在python3.6环境下加载ansible2.5

参考https://www.cnblogs.com/yongdaimi/p/7600052.html,使用git branch -r查看远程分支,git branch -a查看所有分支

  • (.py3-a2.7.8-env) [deploy@ansible ansible]$ git branch -r | grep stable-2.7
      origin/stable-2.7
  • (.py3-a2.7.8-env) [deploy@ansible ansible]$ git checkout stable-2.7  (切换ansible安装版本
    分支 stable-2.7 设置为跟踪来自 origin 的远程分支 stable-2.7。
    切换到一个新分支 'stable-2.7'
  • (.py3-a2.7.8-env) [deploy@ansible ansible]$ git branch
      devel
    * stable-2.7
  • (.py3-a2.7.8-env) [deploy@ansible ansible]$ source /home/deploy/.py3-a2.7.8-env/ansible/hacking/env-setup -q (在虚拟环境下加载ansible2.7

8.验证ansible2.5

  • (.py3-a2.7.8-env) [deploy@ansible ansible]$ ansible --version
    ansible 2.7.8.post0 (stable-2.7 8fba0ab199) last updated 2019/02/23 19:12:52 (GMT +800)
      config file = None
      configured module search path = ['/home/deploy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
      ansible python module location = /home/deploy/.py3-a2.7.8-env/ansible/lib/ansible
      executable location = /home/deploy/.py3-a2.7.8-env/ansible/bin/ansible
      python version = 3.7.2 (default, Feb 23 2019, 18:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

猜你喜欢

转载自blog.csdn.net/qq_33317586/article/details/87304589
今日推荐