CentOS/REHL 6 安裝配置Ansible

來源:互聯網
上載者:User

標籤:

安裝:依賴的軟體包:Jinja2:Python 的一個對設計師友好的現代範本語言PyYAML:Python 的一個 YAML 編碼/反編碼函數庫paramiko:純 Python 編寫的 SSHv2 協議函數庫httplib2:一個功能全面的 HTTP 用戶端函數庫 安裝ansible[[email protected] ~]# yum list|grep -i ansibleFailed to set locale, defaulting to Cansible.noarch                              1.9.2-1.el6                    epelansible-inventory-grapher.noarch            1.0.1-2.el6                    epelansible-lint.noarch                         2.0.1-1.el6                    epel[[email protected] ~]# yum install ansible.noarch ansible-inventory-grapher.noarch ansible-lint.noarch -y 簡單配置:# vim /etc/ansible/ansible.cfgremote_port = 22private_key_file = /root/.ssh/id_rsa # 定義一個group[[email protected] ~]# tail -n 3 /etc/ansible/hosts [myservers]192.168.4.98192.168.2.98 Usage;1. Execute simple command[[email protected] ~]# ansible myservers -m command -a ‘uptime‘192.168.4.98 | success | rc=0 >> 08:23:14 up 61 days,  8:02,  0 users,  load average: 0.00, 0.00, 0.00 192.168.2.98 | success | rc=0 >> 08:23:14 up 61 days, 10:01,  0 users,  load average: 0.00, 0.00, 0.00 2. Cope file from local to remote server.[[email protected] ~]# ansible myservers -m copy -a "src=/root/test.sh dest=/tmp/test.sh owner=root group=root mode=0755"192.168.2.98 | success >> {    "changed": true,    "checksum": "d51e9d0762e103dced4b6bc84e6af6d48ab44762",    "dest": "/tmp/test.sh",    "gid": 0,    "group": "root",    "md5sum": "69eaa9aae1337871c084de2e62b45109",    "mode": "0755",    "owner": "root",    "size": 20,    "src": "/root/.ansible/tmp/ansible-tmp-1437380034.46-279493020985021/source",    "state": "file",    "uid": 0} 192.168.4.98 | success >> {    "changed": true,    "checksum": "d51e9d0762e103dced4b6bc84e6af6d48ab44762",    "dest": "/tmp/test.sh",    "gid": 0,    "group": "root",    "md5sum": "69eaa9aae1337871c084de2e62b45109",    "mode": "0755",    "owner": "root",    "size": 20,    "src": "/root/.ansible/tmp/ansible-tmp-1437380034.47-136677121174897/source",    "state": "file",    "uid": 0} 3. Execute script on remote server.[[email protected] ~]# ansible myservers -m shell -a "sh /tmp/test.sh"192.168.4.98 | success | rc=0 >> 08:14:28 up 61 days,  7:53,  0 users,  load average: 0.00, 0.00, 0.00 192.168.2.98 | success | rc=0 >> 08:14:27 up 61 days,  9:52,  0 users,  load average: 0.00, 0.00, 0.00 4. Install software with yum[[email protected] ~]# ansible myservers -m yum -a ‘name=httpd state=latest‘192.168.4.98 | success >> {    "changed": false,     "msg": "",     "rc": 0,     "results": [        "All packages providing httpd are up to date"    ]} 192.168.2.98 | success >> {    "changed": false,     "msg": "",     "rc": 0,     "results": [        "All packages providing httpd are up to date"    ]} 5. Manage service[[email protected] ~]# ansible myservers -m service -a ‘name=httpd state=started‘192.168.4.98 | success >> {    "changed": false,     "name": "httpd",     "state": "started"} 192.168.2.98 | success >> {    "changed": false,     "name": "httpd",     "state": "started"} 

CentOS/REHL 6 安裝配置Ansible

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.