作为基本学习实践,我在单个文件中构建了一个 ansible 剧本,这样我就可以理解这一切。
我的ansible剧本如下
---
- name: Basic Sanity Check Playbook
hosts: all
gather_facts: no
vars:
ansible_user: ansible
ansible_ssh_pass: your_password_here
tasks:
- name: Check Disk Usage
command: df -h
register: disk_usage
- name: Print Disk Usage
debug:
var: disk_usage.stdout_lines
- name: Check Memory Usage
command: free -m
register: memory_usage
- name: Print Memory Usage
debug:
var: memory_usage.stdout_lines
- name: Check Uptime
command: uptime
register: system_uptime
- name: Print Uptime
debug:
var: system_uptime.stdout_lines
# Inventory Section
- name: Inventory
hosts:
10.0.2.4:
ansible_host: 10.0.2.4
我希望看到连接和结果,但我看到了这个错误
However i get error ERROR! Hosts list must be a sequence or string. Please check your playbook.
只需将脚本的末尾稍微更改为:
# Inventory Section
- name: Inventory
hosts:
- 10.0.2.4
或:
# Inventory Section
- name: Inventory
hosts:
- 10.0.2.4 ansible_host