Ansible 鏁欑▼锛氱畝鍗?Ansible 鍛戒护浠嬬粛 | Linux 涓浗

Posted Linux涓浗

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ansible 鏁欑▼锛氱畝鍗?Ansible 鍛戒护浠嬬粛 | Linux 涓浗相关的知识,希望对你有一定的参考价值。

鍦ㄨ繖涓?Ansible 鏁欑▼涓紝鎴戜滑灏嗗涔犱竴浜涘熀鏈殑 Ansible 鍛戒护鐨勪緥瀛愶紝鎴戜滑灏嗙敤瀹冩潵绠$悊鍩虹璁炬柦銆?
-- Shusain

鑷磋阿
缂栬瘧鑷€€|銆€http://linuxtechlab.com/ansible-tutorial-simple-commands/ 
銆€浣滆€呫€€|銆€Shusain
銆€璇戣€呫€€|銆€geekpi 馃拵 馃拵 鍏辫缈昏瘧锛?span class="mq-16">689 绡?璐$尞鏃堕棿锛?626 澶?/span>

鍦ㄦ垜浠箣鍓嶇殑 Ansible 鏁欑▼涓紝鎴戜滑璁ㄨ浜?nbsp;Ansible 鐨勫畨瑁呭拰閰嶇疆[1]銆傚湪杩欎釜 Ansible 鏁欑▼涓紝鎴戜滑灏嗗涔犱竴浜涘熀鏈殑 Ansible 鍛戒护鐨勪緥瀛愶紝鎴戜滑灏嗙敤瀹冩潵绠$悊鍩虹璁炬柦銆傛墍浠ヨ鎴戜滑鍏堢湅鐪嬩竴涓畬鏁寸殑 Ansible 鍛戒护鐨勮娉曪細

  
    
    
  
  1. $ ansible <group> -m <module> -a <arguments>

鍦ㄨ繖閲岋紝鎴戜滑鍙互鐢ㄥ崟涓富鏈烘垨鐢?nbsp;<group> 浠f浛涓€缁勪富鏈猴紝<arguments> 鏄彲閫夌殑鍙傛暟銆傜幇鍦ㄦ垜浠潵鐪嬬湅涓€浜?Ansible 鐨勫熀鏈懡浠ゃ€?/p>

妫€鏌ヤ富鏈虹殑杩為€氭€?/p>

鎴戜滑鍦ㄤ箣鍓嶇殑鏁欑▼涓篃浣跨敤浜嗚繖涓懡浠ゃ€傛鏌ヤ富鏈鸿繛鎺ョ殑鍛戒护鏄細

  
    
    
  
  1. $ ansible <group> -m ping

閲嶅惎涓绘満

  
    
    
  
  1. $ ansible <group> -a "/sbin/reboot"

妫€鏌ヤ富鏈虹殑绯荤粺淇℃伅

Ansible 鏀堕泦鎵€鏈夎繛鎺ュ埌瀹冧富鏈虹殑淇℃伅銆傝鏄剧ず涓绘満鐨勪俊鎭紝璇疯繍琛岋細

  
    
    
  
  1. $ ansible <group> -m setup | less

鍏舵锛岄€氳繃浼犻€掑弬鏁版潵浠庢敹闆嗙殑淇℃伅涓鏌ョ壒瀹氱殑淇℃伅锛?/p>

  
    
    
  
  1. $ ansible <group> -m setup -a "filter=ansible_distribution"

浼犺緭鏂囦欢

瀵逛簬浼犺緭鏂囦欢锛屾垜浠娇鐢ㄦā鍧?nbsp;copy 锛屽畬鏁寸殑鍛戒护鏄繖鏍风殑锛?/p>

  
    
    
  
  1. $ ansible <group> -m copy -a "src=/home/dan dest=/tmp/home"

绠$悊鐢ㄦ埛

瑕佺鐞嗗凡杩炴帴涓绘満涓婄殑鐢ㄦ埛锛屾垜浠娇鐢ㄤ竴涓悕涓?nbsp;user 鐨勬ā鍧楋紝骞跺涓嬩娇鐢ㄥ畠銆?/p>

鍒涘缓鏂扮敤鎴?/p>

  
    
    
  
  1. $ ansible <group> -m user -a "name=testuser password=<encrypted password>"

鍒犻櫎鐢ㄦ埛

  
    
    
  
  1. $ ansible <group> -m user -a "name=testuser state=absent"

娉ㄦ剰锛?/span> 瑕佸垱寤哄姞瀵嗗瘑鐮侊紝璇蜂娇鐢?nbsp;"mkpasswd -method=sha-512"銆?/p>

鏇存敼鏉冮檺鍜屾墍鏈夎€?/p>

瑕佹敼鍙樺凡杩炴帴涓绘満鏂囦欢鐨勬墍鏈夎€咃紝鎴戜滑浣跨敤鍚嶄负 file 鐨勬ā鍧楋紝浣跨敤濡備笅銆?/p>

鏇存敼鏂囦欢鏉冮檺

  
    
    
  
  1. $ ansible <group> -m file -a "dest=/home/dan/file1.txt mode=777"

鏇存敼鏂囦欢鐨勬墍鏈夎€?/p>

  
    
    
  
  1. $ ansible <group> -m file -a "dest=/home/dan/file1.txt mode=777 owner=dan group=dan"

绠$悊杞欢鍖?/p>

鎴戜滑鍙互閫氳繃浣跨敤 yum 鍜?nbsp;apt 妯″潡鏉ョ鐞嗘墍鏈夊凡杩炴帴涓绘満鐨勮蒋浠跺寘锛屽畬鏁寸殑鍛戒护濡備笅锛?/p>

妫€鏌ュ寘鏄惁宸插畨瑁呭苟鏇存柊

  
    
    
  
  1. $ ansible <group> -m yum -a "name=ntp state=latest"

妫€鏌ュ寘鏄惁宸插畨瑁咃紝浣嗕笉鏇存柊

  
    
    
  
  1. $ ansible <group> -m yum -a "name=ntp state=present"

妫€鏌ュ寘鏄惁鏄壒瀹氱殑鐗堟湰

  
    
    
  
  1. $ ansible <group> -m yum -a "name= ntp-1.8 state=present"

妫€鏌ュ寘鏄惁娌℃湁瀹夎

  
    
    
  
  1. $ ansible <group> -m yum -a "name=ntp state=absent"

绠$悊鏈嶅姟

瑕佺鐞嗘湇鍔★紝鎴戜滑浣跨敤妯″潡 service 锛屽畬鏁村懡浠ゅ涓嬶細

鍚姩鏈嶅姟

  
    
    
  
  1. $ansible <group> -m service -a "name=httpd state=started"

鍋滄鏈嶅姟

  
    
    
  
  1. $ ansible <group> -m service -a "name=httpd state=stopped"

閲嶅惎鏈嶅姟

  
    
    
  
  1. $ ansible <group> -m service -a "name=httpd state=restarted"

杩欐牱鎴戜滑绠€鍗曠殑銆佸崟琛?Ansible 鍛戒护鐨勬暀绋嬪氨瀹屾垚浜嗐€傛澶栵紝鍦ㄦ湭鏉ョ殑鏁欑▼涓紝鎴戜滑灏嗗涔犲垱寤?playbook锛屾潵甯姪鎴戜滑鏇磋交鏉鹃珮鏁堝湴绠$悊涓绘満銆?/p>


via: http://linuxtechlab.com/ansible-tutorial-simple-commands/

鏈枃鐢?nbsp;LCTT 鍘熷垱缂栬瘧锛?span class="mq-301">Linux涓浗 鑽h獕鎺ㄥ嚭


以上是关于Ansible 鏁欑▼锛氱畝鍗?Ansible 鍛戒护浠嬬粛 | Linux 涓浗的主要内容,如果未能解决你的问题,请参考以下文章

ansible入门讲解

ansible入门讲解

ansible使用

Ansible之ansible.cfg

ansible源码解读

ansible总结