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

Ansible

出自H.-H.'s Wiki

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 查看。

參考資料