官網鏈接:https://docs.ansible.com/ansible/latest/modules/list_of_all_modules.html
ansible python module location = ~/python3.x/site-packages/ansible-2.7.8.post0-py3.x.egg/ansible/modules/
File模塊
在目錄主機創建文件或目錄,並賦予其系統權限
- name: create file
file: 'path=/tmp/test.txt state=touch mode=0755 owner=user01 group=user01'
Copy模塊
實現Ansible服務端到目標主機的文件傳送
- name: copy file
copy: 'remote_src=no src=/tmp/test.txt dest=/tmp/test.txt mode=0644 force=yes'
Stat模塊
獲取遠程文件狀態信息
- name: check if text.txt exists
stat: 'path=/tmp/text.txt'
register: script_stat # 將stat結果賦值給 script_stat
Debug模塊
打印語句到Ansible執行輸出
- debug: msg=text.txt exists
when: script_stat.stat.exists # 跟Stat模塊配合使用
Command/Shell模塊
用來執行Linux目標主機命令,區別為:Shell —— 會調用系統中的/bin/bash,這樣就可以使用系統中的環境變量,例如重新向,管道符。
- name: run a script
command: 'echo "hello world"'
Template模塊
實現Ansible服務端到目標主機的jinja2模板傳送
- name: write the nginx config file
template: src=/tmp/nginx.conf.j2 dest=/etc/nginx/nginx.conf
Packaging模塊
調用目標主機系統包管理工具(yum, apt)進行安裝
- name: ensure nginx is at the latest version
yum: pkg=nginx state=latest
- name: ensure nginx is at the latest version
apt: pkg=nginx state=latest
Service模塊
管理目標主機系統服務
- name: start nginx service
service: name=nginx state=started