Ansible无法连接到内存库存中定义的Windows主机

时间:2018-04-01 14:22:53

标签: ansible

我正在尝试在Azure上创建一个新的Windows主机,将其添加到Ansible的内存中库存并对其进行游戏。然而似乎Ansible正在尝试使用ssh连接到我的Windows主机。

以下是我的剧本

- name: Windows VM Playbook
  hosts: localhost

  vars:
    nicName: "Blue-xxxx"
    vmName:  "Blue-xxxx"
    vmPubIp: "51.141.x.x"


  tasks:
  - name: Create Windows VM
    azure_rm_virtualmachine:
      resource_group: AnsibleVMxxx
      name: "{{ vmName }}"
      vm_size: Standard_B2ms
      storage_account: vmstoragedisksxxx
      admin_username: xxxxxxxx
      admin_password: xxxxxxxx
      network_interface_names: "{{ nicName }}"
      managed_disk_type: Standard_LRS
      data_disks:
          - lun: 0
            disk_size_gb: 64
            managed_disk_type: Standard_LRS
            storage_container_name: vhd
            storage_account_name: AnsibleVMxxxxtorageaccount
      os_type: Windows
      image:
        offer: "WindowsServer"
        publisher: MicrosoftWindowsServer
        sku: '2012-R2-Datacenter'
        location: 'uk west'
        version: latest

  - name: Custom Script Extension
    azure_rm_deployment:
      state: present
      location: 'uk west'
      resource_group_name: 'AnsibleVMxxxx'
      template: "{{ lookup('file', '/etc/ansible/playbooks/ConfigureAnsibleForPowershellRemoting.json') | from_json }}"
      deployment_mode: incremental
      parameters:
        vmName:
          value: "{{ vmName }}"


  - name: Add machine to in-memory inventory_plugins
    add_host:
      name: 51.141.x.x
      groups: webservers
      ansible_user: adminUser
      ansible_password: xxxxxxxx
      ansible_port: 5986
      ansible_connection: winrm
      ansible_winrm_server_cert_validation: ignore
      ansible_winrm_scheme: https


  - name: Ping
    hosts: webservers
    gather_facts: false
    connection: local
    win_ping:

我在/ playbooks / group_vars文件夹下还有一个webserver.yml文件,内容如下

    ansible_user: adminUser
    ansible_password: xxxxxxxx
    ansible_port: 5986
    ansible_connection: winrm
    ansible_winrm_server_cert_validation: ignore
    ansible_winrm_scheme: https

有谁能告诉我我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

想出来。

问题出现了,因为我在剧本开头有主持人:localhost。我不得不将依赖于内存库存的游戏移出localhost块。