Ansible-是否可以使用Ansible更改Windows Server IP地址?

时间:2020-02-12 05:43:41

标签: ansible

我想使用Ansible设置新的域控制器。我有一个从模板克隆新服务器的脚本,现在如何使用Ansible静态设置Windows Server的IP地址?

1 个答案:

答案 0 :(得分:2)

花了好几个小时找到相同问题的答案:)希望对您有所帮助:

- name: Set up static IP address
  win_shell: "Get-NetIpAddress -InterfaceAlias 'Ethernet' | New-NetIpAddress -IpAddress 192.168.1.120 -PrefixLength 24 -DefaultGateway 192.168.1.1"
  async: 100 # Using "fire-and-forget" asynchronous execution for this task, otherwise it will always fail and timeout
  poll: 0

- name: Change ansible's ip address for each host
  set_fact:
    ansible_host: "192.168.1.120"

- name: Wait for the hosts network interface to come back up
  local_action:
    module: wait_for
    host: "{{ ansible_host }}"
    port: 5985
    delay: 10
    state: started
  register: wait_result

- name: Create a test folder to celebrate success
  win_file:
    path: C:\itworks
    state: directory