centos8平台安裝ansible2.9


一,ansible的用途:

ansible是基於python開發的自動化運維工具,

它基於SSH遠程連接服務,

可以實現批量系統配置、批量軟件部署、批量文件拷貝、批量運行命令等多個運維功能

因為基於ssh連接,所以只需要受控端運行openssh服務即可,無需運行其他服務

只需主控端安裝ansible即可

 

說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest

         對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/

 說明:作者:劉宏締 郵箱: 371125307@qq.com

 

二,ansible所屬的源是epel

[root@centos8 liuhongdi]# dnf info ansible
上次元數據過期檢查:0:01:12 前,執行於 2020年04月18日 星期六 14時39分54秒。
可安裝的軟件包
名稱         : ansible
版本         : 2.9.5
發布         : 1.el8
架構         : noarch
大小         : 17 M
源           : ansible-2.9.5-1.el8.src.rpm
倉庫         : epel
概況         : SSH-based configuration management, deployment, and task execution system
URL          : http://ansible.com
協議         : GPLv3+
描述         : Ansible is a radically simple model-driven configuration management,
             : multi-node deployment, and remote task execution system. Ansible works
             : over SSH and does not require any software or daemons to be installed
             : on remote nodes. Extension modules can be written in any language and
             : are transferred to managed machines automatically.

 

如果沒有安裝epel源,執行以下命令安裝epel源:

[root@centos8 liuhongdi]# dnf install epel-release

 

三,dnf安裝ansible

[root@centos8 liuhongdi]# dnf install ansible

 

四,查看ansible的版本和幫助

1,查看版本

[root@centos8 liuhongdi]# ansible --version
ansible 2.9.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Nov 21 2019, 19:31:34) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]

 

2,查看幫助

[root@centos8 liuhongdi]# ansible --help

 

3,查看手冊:

[root@centos8 liuhongdi]# man ansible

 

五,測試是否能連接成功?(使用密碼)

1,編輯ansible的配置文件

[root@centos8 liuhongdi]# vi /etc/ansible/hosts 

 

內容:

#ansible_ssh_user: 指定用戶名

#ansible_ssh_pass: 指定密碼

[yujian]
121.122.123.47:12888 ansible_ssh_user=webop ansible_ssh_pass="weboppass"

 

2,檢查是否能連接到服務器

[liuhongdi@centos8 ~]$ ansible -m ping yujian
121.122.123.47 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

連接成功

 

六,測試是否能連接成功?(使用密鑰)

1,生成密鑰

[liuhongdi@centos8 ~]$ ssh-keygen -t rsa

 

2,上傳密鑰到服務器:

[liuhongdi@centos8 ~]$ ssh-copy-id -p 12888 webop@121.122.123.47

 

3,登錄到受控端的服務器檢查,是否已把key寫入

[webop@blog ~]$ more .ssh/authorized_keys

 

4,編輯配置文件,不再需要指定密碼

[root@centos8 liuhongdi]# vi /etc/ansible/hosts 

內容:

[yujian]
121.122.123.47:12888 ansible_ssh_user=webop

 

5,再次測試是否能連接

[liuhongdi@centos8 ~]$ ansible -m ping yujian
121.122.123.47 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

成功了

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM