切換選單
切換偏好設定選單
切換個人選單
尚未登入
若您做出任何編輯,會公開您的 IP 位址。

「Ansible」:修訂間差異

出自H.-H.'s Wiki
Hsins留言 | 貢獻
建立內容為「'''Ansible''' 是使用 Python 程式語言開發與實作的一款系統環境自動化與管理工具,主要透過 SSH 協定與節點進行通訊,不需要在節點上安裝客戶端,配置語法使用 YAML 與 Jinja2 模板語言。」的新頁面
 
Hsins留言 | 貢獻
無編輯摘要
 
第1行: 第1行:
'''Ansible''' 是使用 [[Python]] 程式語言開發與實作的一款系統環境自動化與管理工具,主要透過 SSH 協定與節點進行通訊,不需要在節點上安裝客戶端,配置語法使用 YAML 與 Jinja2 模板語言。
'''Ansible''' 是使用 [[Python]] 程式語言開發與實作的一款系統環境自動化與管理工具,主要透過 SSH 協定與節點進行通訊,不需要在節點上安裝客戶端,配置語法使用 YAML 與 Jinja2 模板語言。
== 臨時命令(Ad-hoc Command) ==
'''臨時命令(Ad-hoc Command)'''是指使用 <code>ansible</code> 二進制執行文件,臨時執行且不需要保存的命令,其執行依賴於 Ansible Module 如 <code>command</code>、<code>raw</code>、<code>shell</code>、<code>file</code> 和 <code>cron</code> 等,執行完畢會返回 JSON 格式的資訊。
一些常用的臨時命令如下:<syntaxhighlight lang="bash">
# Ping Hosts
$ ansible managednodes -m ansible.builtin.ping
# Display Facts
$ ansible managednodes -m ansible.builtin.setup
$ ansible managednodes -m ansible.builtin.setup -a "filter=ansible_distribution*"
# Copy a File from Control Node to All Managed Nodes
$ ansible managednodes -m ansible.builtin.copy -a "src=/etc/hostname dest=/tmp/hostname"
# Create a Directory on All Managed Nodes with Specific Ownership and Permissions
$ ansible managednodes -m ansible.builtin.file -a "dest=/tmp/newpath mode=777 owner=james group=james state=directory"
# Delete a Directory on All Managed Nodes
$ ansible managednodes -m ansible.builtin.file -a "dest=/tmp/newpath state=absent"
# Install Packages
$ ansible managednodes -m ansible.builtin.apt -a "name=apache2 state=present" --become
$ ansible managednodes -m ansible.builtin.apt -a "name=apache2 state=latest" --become
</syntaxhighlight>
* 官方所提供的模組可以使用 <code>ansible-doc -l</code> 查看。
* 如果想要查看某個模組的參數,可以使用 <code>ansible-doc -s module</code> 查看。
== 參考資料 ==
* [https://clay-wangzhi.com/devops/ansible/ SRE 運維進階之路|Ansible 學習筆記]

於 2025年3月11日 (二) 02:52 的最新修訂

Ansible 是使用 Python 程式語言開發與實作的一款系統環境自動化與管理工具,主要透過 SSH 協定與節點進行通訊,不需要在節點上安裝客戶端,配置語法使用 YAML 與 Jinja2 模板語言。

臨時命令(Ad-hoc Command)

臨時命令(Ad-hoc Command)是指使用 ansible 二進制執行文件,臨時執行且不需要保存的命令,其執行依賴於 Ansible Module 如 commandrawshellfilecron 等,執行完畢會返回 JSON 格式的資訊。

一些常用的臨時命令如下:

# Ping Hosts
$ ansible managednodes -m ansible.builtin.ping

# Display Facts
$ ansible managednodes -m ansible.builtin.setup
$ ansible managednodes -m ansible.builtin.setup -a "filter=ansible_distribution*"

# Copy a File from Control Node to All Managed Nodes
$ ansible managednodes -m ansible.builtin.copy -a "src=/etc/hostname dest=/tmp/hostname"

# Create a Directory on All Managed Nodes with Specific Ownership and Permissions
$ ansible managednodes -m ansible.builtin.file -a "dest=/tmp/newpath mode=777 owner=james group=james state=directory"

# Delete a Directory on All Managed Nodes
$ ansible managednodes -m ansible.builtin.file -a "dest=/tmp/newpath state=absent"

# Install Packages
$ ansible managednodes -m ansible.builtin.apt -a "name=apache2 state=present" --become
$ ansible managednodes -m ansible.builtin.apt -a "name=apache2 state=latest" --become
  • 官方所提供的模組可以使用 ansible-doc -l 查看。
  • 如果想要查看某個模組的參數,可以使用 ansible-doc -s module 查看。

參考資料