Excerpts from lars svenson's message of 2013-07-11 13:13:07 -0400:
> - name: add auth lines to auth via .htpasswd to
> /etc/apache2/sites-available/$DOMAIN
> action: lineinfile dest=/etc/apache2/sites-available/$DOMAIN
> regexp='^[\W]*allow'
> line=' AuthType Basic'
> insertafter='^[\W]*allow'
> state=present
>
> Ansible does find the right line, but replaces the " allow"-line with
> "AuthType Basic". Nor insertafter, neither insertbefore are working - just
> replacing.
The 'regexp' parameter is meant to match the line being inserted, not
the line you want to insert after. If the regex matches any line in the
file, then the contents of 'line' will *not* be inserted, ensuring
idempotency. So, in your case, you'd want 'regexp' to be
' AuthType Basic'.
Note that this will match that line *anywhere* in the file, so if it
occurs more than once, it will not get inserted, even if its occurrence
is not after the line matching 'lineafter'.
I *think* you can get clever here with back-references and whatnot, but
I'm not positive.
--
Morgan