blockinfile

19 views
Skip to first unread message

Erick K

unread,
Feb 9, 2016, 3:54:59 PM2/9/16
to Ansible Project
I want to add new hosts to an http configuration file. When I use blockinfile it's replacing the last block and not appending to the end. What I'd like to do is keep adding to the file but blockfile doesn't seem to be doing what I want. 

<VirtualHost *:*>
  ServerAdmin someone
  DocumentRoot /var/www/html/prod/liver
  ServerName liver
  ServerAlias www.liver
</VirtualHost>
<VirtualHost *:*>
  ServerAdmin someone
  DocumentRoot /var/www/html/prod/liver
  ServerName liver
  ServerAlias www.liver
</VirtualHost>


My code

---
- hosts: web
  vars_prompt:
    - name: "site"
      prompt: "Enter application"
      private: no

  tasks:
  - name: "append"
    blockinfile:
      dest: /tmp/xxxyyy
      insertafter: "# {mark} ANSIBLE MANAGED BLOCK"
      block: |
        <VirtualHost *:*>
          ServerAdmin someone
          DocumentRoot /var/www/html/prod/{{site}}
          ServerName {{site}}
          ServerAlias www.{{site}}
        </VirtualHost>


Reply all
Reply to author
Forward
0 new messages