Cas*_*sie 4 ssh ansible ubuntu-14.04
我根据本教程创建了我的第一个 ansible playbook ,所以它看起来像这样:
---
- hosts: hostb
tasks:
- name: Create file
file:
path: /tmp/yallo
state: touch
- hosts: my_hosts
sudo: yes
tasks:
- name: Create user
user:
name: mario
shell: /bin/zsh
- name: Install zlib
yum:
name: zlib
state: latest
Run Code Online (Sandbox Code Playgroud)
但是,我不知道应该将哪些主机放入我的主机文件中。我现在有这样的事情:
[my_hosts]
hostA
hostB
Run Code Online (Sandbox Code Playgroud)
显然,它不起作用,我明白了:
ssh: Could not resolve hostname hostb: Name or service not known
Run Code Online (Sandbox Code Playgroud)
那么我应该如何更改我的主机文件?我是 ansible 的新手,所以我将非常感谢您的帮助!
好的,所以 Ansible 清单可以基于以下格式:
IP AddressDHCP or Hosts file hostname reference localhost/cassie.localhostname ansible_host=IP Address[group_name]这是您可以使用的最基本的结构。
例子
# Grouping
[test-group]
# IP reference
192.168.1.3
# Local hosts file reference
localhost
# Create your own alias
test ansible_host=192.168.1.4
# Create your alias with port and user to login as
test-2 ansible_host=192.168.1.5 ansible_port=1234 ansible_user=ubuntu
Run Code Online (Sandbox Code Playgroud)
主机分组仅在检测到文件结尾或另一个组时才会结束。因此,如果您希望拥有不属于某个组的主机,请确保将它们定义在组定义之上。
IE 上例中的所有内容都属于test-group,如果您执行以下操作;它将在所有主机上执行:
ansible test-group -u ubuntu -m ping
| 归档时间: |
|
| 查看次数: |
11115 次 |
| 最近记录: |