【问题标题】:Ansible playbook example code fail to runAnsible playbook 示例代码无法运行
【发布时间】:2019-10-22 10:05:18
【问题描述】:

我开始尝试 Ansible,并使用 Ansible 文档中的示例代码。在我尝试了几个示例之后,我在代码的开头得到了错误。它说

- name: Change the hostname to Windows_Ansible
  ^ here(Point at name)" 

任何建议将不胜感激。

我试过这个 https://docs.ansible.com/ansible/latest/modules/win_hostname_module.html#win-hostname-module

---

- name: Change the hostname to Windows_Ansible
  win_hostname:
    name: "Windows_Ansible"
  register: res

- name: Reboot
  win_reboot:
  when: res.reboot_required

【问题讨论】:

标签: ansible yaml


【解决方案1】:

以下任务将更改服务器的主机名。确保您在测试服务器上运行,这样它就不会产生问题。如果您只是想测试一些剧本,请使用带有 win_command 的第二个剧本

---
- hosts: <remote server name which needs to be added in the inventory>
  tasks:
  - name: Change the hostname to Windows_Ansible
    win_hostname:
      name: "Windows_Ansible"
    register: res

  - name: Reboot
    win_reboot:
    when: res.reboot_required
---
- hosts: <remote server name which needs to be added in the inventory>
  tasks:
  - name: Test
    win_command: whoami
    register: res

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多