ansible

環境準備:
管理機ip(類比服務端ip): 192.168.124.73
被管理機ip(類比客戶端ip):192.168.124.147
1.安裝ansible
yum install ansible -y
2.查看ansible版本
ansible --version
3.生成公鑰私鑰
ssh-keygen

Enter passphrase (empty for no passphrase):(回車)
Enter same passphrase again:(回車)
4.進到.ssh目錄下
cd .ssh

5.將公鑰上傳到被管理機
ssh-copy-id -i [email protected](被管理機ip)

Are you sure you want to continue connecting (yes/no)? yes
[email protected]'s password: (輸入被管理機的密碼)

此時 被管理機的.ssh目錄下會自動生成一個 authorized_keys(認證過的密鑰)

  1. 編輯配置文件
    vim /etc/ansible/hosts

在末端添加一個模塊
[test-servers]
192.168.124.147(被管理機ip)
7.測試連接
ansible -m ping 'test-servers'

會出現:
192.168.1.129 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
8.此時我們可以測試操作一下,將管理機上家目錄下的we.sh文件傳到被管理機的/tmp目錄下
ansible test-servers -m copy -a "src=/root/we.sh dest=/tmp/ owner=root group=root mode=0755 force=yes"

此時,在管理機上會顯示傳輸成功
在被管理機的/tmp目錄下會接收到管理機傳輸的文件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章