1. 準備主機組
[root@ansible-master ansible_quickstart]# vim inventory/hosts
[web:vars]
ansible_port=22
ansible_password='Admin@123456'[web]
192.168.100.182
2.準備劇本 vim hello.yml
---
- hosts: webremote_user: roottasks:- name: Ping the target hostsping:- name: 獲取操作系統信息command: cat /etc/os-releaseregister: os_info- name: 顯示操作系統信息debug:var: os_info.stdout- name: 查看時間shell: /usr/bin/dateregister: date_output- name: 顯示時間結果debug:var: date_output.stdout
3.執行具備查看結果
ansible-playbook hello.yml