Sup*_*Das 10 ansible ansible-playbook
我有下面的剧本,其中远程主机是用户输入,随后我试图收集有关远程主机的事实并将其复制到本地文件:
---
- hosts: localhost
vars_prompt:
name: hostname
prompt: "Enter Hostname"
tasks:
- name: Add hosts to known_hosts file
add_host: name={{ hostname }} groups=new
- name: Check if Host is reachable
shell: ansible -m ping {{ hostname }}
- name: Remove existing remote hosts
shell: ssh-keygen -R {{ hostname }}
- name: Setup passwordless SSH login
shell: ssh-copy-id -i ~/.ssh/id_rsa user@{{ hostname }}
- name: Display facts
command: ansible {{ groups['new'] }} -m setup
register: output
- copy: content="{{ output }}" dest=/var/tmp/dir/Node_Health/temp
...
Run Code Online (Sandbox Code Playgroud)
我在temp文件中收到以下错误:
Node_Health]# cat temp
{"start": "2016-06-17 09:26:59.174155", "delta": "0:00:00.279268", "cmd": ["ansible", "[udl360x4675]", "-m", "setup"], "end": "2016-06-17 09:26:59.453423", "stderr": " [WARNING]: provided hosts list is empty, only localhost is available", "stdout": "", "stdout_lines": [], "changed": true, "rc": 0, "warnings":
Run Code Online (Sandbox Code Playgroud)
我也试过下面的剧本也给出了同样的错误:
---
- hosts: localhost
vars_prompt:
name: hostname
prompt: "Enter Hostname"
tasks:
- name: Add hosts to known_hosts file
add_host: name={{ hostname }} groups=new
- name: Check if Host is reachable
shell: ansible -m ping {{ hostname }}
- name: Remove existing remote hosts
shell: ssh-keygen -R {{ hostname }}
- name: Setup passwordless SSH login
shell: ssh-copy-id -i ~/.ssh/id_rsa user@{{ hostname }}
- hosts: new
tasks:
- name: Display facts
command: ansible {{ groups['new'] }} -m setup
register: output
- local_action: copy content="{{ output }}" dest=/var/tmp/dir/Node_Health/temp
...
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
将您的主机放入一个hosts.ini文件中,语法如下:
[nodes]
node_u1 ansible_user=root ansible_host=127.0.0.1
node_u2 ansible_user=root ansible_host=127.0.1.1
node_u3 ansible_user=root ansible_host=127.0.2.1
node_u4 ansible_user=root ansible_host=127.0.3.1
node_u5 ansible_user=root ansible_host=127.0.4.1
Run Code Online (Sandbox Code Playgroud)
运行ansible,使用:ansible-playbook -i ports.ini
您还可以保存主机文件/etc/ansible/hosts以避免将主机作为参数传递。Ansible 将其视为默认位置。然后只需使用以下命令运行:
ansible-playbook <playbook.yml>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41382 次 |
| 最近记录: |