Adding Multiple Lines to file (Windows Servers)

83 views
Skip to first unread message

Mark Matthews

unread,
Feb 11, 2016, 5:34:55 AM2/11/16
to Ansible Project
Hi

I am trying to add multiple lines to the host file on some Windows servers.

If I use the following playbook I can add one line:

---
- name: Add host file entries
  hosts: all
  tasks:
    - name: Check if line is present in config
      win_lineinfile:
        dest: C:\Windows\System32\drivers\etc\hosts
        line: "x.x.x.x   www.website1.com"


I have tried the following, but keep getting errors:

---
- name: Add host file entries
  hosts: all
  tasks:
    - name: Add host file entries
      blockinfile:
        dest: C:\Windows\System32\drivers\etc\hosts
        block: 
          10.10.3.76   www.website1.com
          10.10.3.77   www.website1.com
          10.10.3.19   www.website1.com
          10.10.10.2   www.website1.com
          10.10.3.74   www.website1.com


Does anyone know of way that this can be done?

J Hawkesworth

unread,
Feb 11, 2016, 6:38:51 AM2/11/16
to Ansible Project
blockinfile is not a windows module unfortunately.

There is an as yet un merged module for manipulating the windows hosts file though - perhaps give that a try - https://github.com/ansible/ansible-modules-extras/pull/1455

Hope that helps,

Jon

Mark Matthews

unread,
Feb 11, 2016, 11:59:16 AM2/11/16
to Ansible Project
Thanks Jon

I will take a look at the link and see if it can help me.

Cheers
Reply all
Reply to author
Forward
0 new messages