Thanks, think I found my rookie mistake, I have used the --check flag
liberally when testing the playbooks, but that of course causes problems in
this case since it does not create the file because of that, and then the
rest of the playbook fails.
On Wednesday, October 19, 2016 at 5:08:23 PM UTC+2, Daniel Delin wrote:
>
> Hi,
>
> New to Ansible, evaluating it for replacing Cfengine.
> One feature we use frequently is the replacement of a block of text within
> a file, and the Ansible blockinfile module looks to be just that.
>
> However I run in to problems adding a block of text to a file if it does
> not already exist. I have tried with this code:
>
> - name: Add mappings to /tmp/hosts
> blockinfile:
> dest: /tmp/hosts
> state: present
> create: yes
> block: |
> destination logserver1 { tcp("xx.xx.xx.xx" port(514)); };
> destination logserver2 { tcp("xx.xx.x.x" port(514)); };
> log { source(src); destination(logserver1); };
> log { source(src); destination(logserver2); };
> log { source(src); destination(logserver3); };
> destination logserver3 { tcp("x.x.xx.xxx" port(5000)); };
> marker: "# {mark} ANSIBLE HOSTS BLOCK "
>
> When I run this it bails out because of the create: yes line, if I comment
> that out it runs through, but of course does not create the file, and
> therefore fails the blockedit. If I create an empty file manually it works
> as intended. According to the docs, both state and create are supported by
> the blockinfile module.
>
> Ansible version is 2.1.2.0
>
>
> Help appreciated
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/3b4ae552-ff5d-4525-aaf5-9ba04fd8c7d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.