Ansible 鏁欑▼锛氱畝鍗?Ansible 鍛戒护浠嬬粛 | Linux 涓浗
Posted Linux涓浗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ansible 鏁欑▼锛氱畝鍗?Ansible 鍛戒护浠嬬粛 | Linux 涓浗相关的知识,希望对你有一定的参考价值。
銆€浣滆€呫€€|銆€Shusain
銆€璇戣€呫€€|銆€geekpi 馃拵 馃拵 鍏辫缈昏瘧锛?span class="mq-16">689 绡?璐$尞鏃堕棿锛?626 澶?/span>
鍦ㄦ垜浠箣鍓嶇殑 Ansible 鏁欑▼涓紝鎴戜滑璁ㄨ浜?nbsp;Ansible 鐨勫畨瑁呭拰閰嶇疆[1]銆傚湪杩欎釜 Ansible 鏁欑▼涓紝鎴戜滑灏嗗涔犱竴浜涘熀鏈殑 Ansible 鍛戒护鐨勪緥瀛愶紝鎴戜滑灏嗙敤瀹冩潵绠$悊鍩虹璁炬柦銆傛墍浠ヨ鎴戜滑鍏堢湅鐪嬩竴涓畬鏁寸殑 Ansible 鍛戒护鐨勮娉曪細
$ ansible <group> -m <module> -a <arguments>
鍦ㄨ繖閲岋紝鎴戜滑鍙互鐢ㄥ崟涓富鏈烘垨鐢?nbsp;<group>
浠f浛涓€缁勪富鏈猴紝<arguments>
鏄彲閫夌殑鍙傛暟銆傜幇鍦ㄦ垜浠潵鐪嬬湅涓€浜?Ansible 鐨勫熀鏈懡浠ゃ€?/p>
妫€鏌ヤ富鏈虹殑杩為€氭€?/p>
鎴戜滑鍦ㄤ箣鍓嶇殑鏁欑▼涓篃浣跨敤浜嗚繖涓懡浠ゃ€傛鏌ヤ富鏈鸿繛鎺ョ殑鍛戒护鏄細
$ ansible <group> -m ping
閲嶅惎涓绘満
$ ansible <group> -a "/sbin/reboot"
妫€鏌ヤ富鏈虹殑绯荤粺淇℃伅
Ansible 鏀堕泦鎵€鏈夎繛鎺ュ埌瀹冧富鏈虹殑淇℃伅銆傝鏄剧ず涓绘満鐨勪俊鎭紝璇疯繍琛岋細
$ ansible <group> -m setup | less
鍏舵锛岄€氳繃浼犻€掑弬鏁版潵浠庢敹闆嗙殑淇℃伅涓鏌ョ壒瀹氱殑淇℃伅锛?/p>
$ ansible <group> -m setup -a "filter=ansible_distribution"
浼犺緭鏂囦欢
瀵逛簬浼犺緭鏂囦欢锛屾垜浠娇鐢ㄦā鍧?nbsp;copy
锛屽畬鏁寸殑鍛戒护鏄繖鏍风殑锛?/p>
$ ansible <group> -m copy -a "src=/home/dan dest=/tmp/home"
绠$悊鐢ㄦ埛
瑕佺鐞嗗凡杩炴帴涓绘満涓婄殑鐢ㄦ埛锛屾垜浠娇鐢ㄤ竴涓悕涓?nbsp;user
鐨勬ā鍧楋紝骞跺涓嬩娇鐢ㄥ畠銆?/p>
鍒涘缓鏂扮敤鎴?/p>
$ ansible <group> -m user -a "name=testuser password=<encrypted password>"
鍒犻櫎鐢ㄦ埛
$ ansible <group> -m user -a "name=testuser state=absent"
娉ㄦ剰锛?/span> 瑕佸垱寤哄姞瀵嗗瘑鐮侊紝璇蜂娇鐢?nbsp; 鏇存敼鏉冮檺鍜屾墍鏈夎€?/p>
瑕佹敼鍙樺凡杩炴帴涓绘満鏂囦欢鐨勬墍鏈夎€咃紝鎴戜滑浣跨敤鍚嶄负 鏇存敼鏂囦欢鏉冮檺 鏇存敼鏂囦欢鐨勬墍鏈夎€?/p>
绠$悊杞欢鍖?/p>
鎴戜滑鍙互閫氳繃浣跨敤 妫€鏌ュ寘鏄惁宸插畨瑁呭苟鏇存柊 妫€鏌ュ寘鏄惁宸插畨瑁咃紝浣嗕笉鏇存柊 妫€鏌ュ寘鏄惁鏄壒瀹氱殑鐗堟湰 妫€鏌ュ寘鏄惁娌℃湁瀹夎 绠$悊鏈嶅姟 瑕佺鐞嗘湇鍔★紝鎴戜滑浣跨敤妯″潡 鍚姩鏈嶅姟 鍋滄鏈嶅姟 閲嶅惎鏈嶅姟 杩欐牱鎴戜滑绠€鍗曠殑銆佸崟琛?Ansible 鍛戒护鐨勬暀绋嬪氨瀹屾垚浜嗐€傛澶栵紝鍦ㄦ湭鏉ョ殑鏁欑▼涓紝鎴戜滑灏嗗涔犲垱寤?playbook锛屾潵甯姪鎴戜滑鏇磋交鏉鹃珮鏁堝湴绠$悊涓绘満銆?/p>
via: http://linuxtechlab.com/ansible-tutorial-simple-commands/ 鏈枃鐢?nbsp;LCTT 鍘熷垱缂栬瘧锛?span class="mq-301">Linux涓浗"mkpasswd -method=sha-512"
銆?/p>
file
鐨勬ā鍧楋紝浣跨敤濡備笅銆?/p>
$ ansible <group> -m file -a "dest=/home/dan/file1.txt mode=777"
$ ansible <group> -m file -a "dest=/home/dan/file1.txt mode=777 owner=dan group=dan"
yum
鍜?nbsp;apt
妯″潡鏉ョ鐞嗘墍鏈夊凡杩炴帴涓绘満鐨勮蒋浠跺寘锛屽畬鏁寸殑鍛戒护濡備笅锛?/p>
$ ansible <group> -m yum -a "name=ntp state=latest"
$ ansible <group> -m yum -a "name=ntp state=present"
$ ansible <group> -m yum -a "name= ntp-1.8 state=present"
$ ansible <group> -m yum -a "name=ntp state=absent"
service
锛屽畬鏁村懡浠ゅ涓嬶細
$ansible <group> -m service -a "name=httpd state=started"
$ ansible <group> -m service -a "name=httpd state=stopped"
$ ansible <group> -m service -a "name=httpd state=restarted"
以上是关于Ansible 鏁欑▼锛氱畝鍗?Ansible 鍛戒护浠嬬粛 | Linux 涓浗的主要内容,如果未能解决你的问题,请参考以下文章