天天看點

自動化運維利器(Ansible)一

Ansible 介紹及安裝

1. 介紹、

  • Ansible 是一個 IT 自動化工具。它能配置系統、部署軟體、編排更複雜的 IT 任務,如連續部署或零停機時間滾動更新。
  • Ansible 用 Python 編寫,盡管市面上已經有很多可供選擇的配置管了解決方案(例如 saltstack、Puppet、Chef等),但它們各有優劣,而Ansible的特點在于它的簡潔。讓 Ansible 在主流的配置管理系統中與衆不同的一點便是,它并不需要你在想要配置的每個節點上安裝自己的元件。同時提供的另一個優點,如果需要的話,你可以在不止一個地方控制你的整個基礎架構。

2. 工作原理

自動化運維利器(Ansible)一
  • 1、在ANSIBLE 管理體系中,存在"管理節點" 和 “被管理節點” 兩種角色。
  • 2、被管理節點通常被稱為"資産"
  • 3、在管理節點上,Ansible将 AdHoc 或 PlayBook 轉換為Python腳本。
并通過SSH将這些Python 腳本傳遞到被管理伺服器上。

 在被管理伺服器上依次執行,并實時的将結果傳回給管理節點。
           

3. 如何安裝

自動化運維利器(Ansible)一

先決條件

管理節點

  • 确儲存在OpenSSH
  • 確定Python 版本 >= 2.6
  • 確定安裝ansible

被管理節點

  • 确儲存在OpenSSH
  • 確定Python 版本 >= 2.4 //若為2.4 版本,確定安裝了python-samplesjson 擴充
  • 不需要安裝ansible

安裝Ansible

  • yun安裝
[[email protected] ~]# yum install epel-release
[[email protected] ~]# yum install ansible  
           
  • pip安裝

    這裡是使用系統自帶的 python2 的環境

    如果系統中安裝的 pip ,可以直接使用 pip 安裝 ansible

[[email protected] ~]# yum install epel-release
[[email protected] ~]# yum install python2-pip
[[email protected] ~]# pip install ansible
           
  • 檢視版本
[[email protected] ~]# ansible --version
ansible 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]