The regexp needs to match the line being added.
On Fri, Mar 21, 2014 at 8:20 AM, Matt Martz <[email protected]> wrote: > I believe what you are doing is constantly overwriting the last line. > > I think, based on the examples and my testing, you would simply want to do: > > vars: > limits_lines: > - 'root soft nofile 65535' > - 'root hard nofile 65535' > - 'root soft memlock unlimited' > - 'root hard memlock unlimited' > > > tasks: > - name: append string > lineinfile: dest=/etc/security/limits.conf > > line="{{item}}" > with_items: limits_lines > > -- > Matt Martz > [email protected] > > On March 21, 2014 at 12:10:24 AM, Mark Conlin ([email protected]) > wrote: > > > I would like to add a few lines to the end of a config file using > lineinfile and with_items. > > When I run this yaml, I see changed log messages for all four entries (see > below). However when I look at the file, only the very last line has been > added. > Your thoughts? > > Thanks, > Mark > > > vars: > limits_lines: > - { key: '', value: 'root soft nofile 65535'} > - { key: '', value: 'root hard nofile 65535'} > - { key: '', value: 'root soft memlock unlimited'} > - { key: '', value: 'root hard memlock unlimited'} > > tasks: > - name: append string > lineinfile: dest=/etc/security/limits.conf > regexp={{item.key}} > insertafter=EOF > line="{{item.value}}" > with_items: limits_lines > > > Output: > <127.0.0.1> REMOTE_MODULE lineinfile dest=/etc/security/limits.conf > regexp= insertafter=EOF line="root soft nofile 65535" > changed: [machine] => (item={'key': '', 'value': 'root soft nofile > 65535'}) => {"backup": "", "changed": true, "item": {"key": "", "value": > "root soft nofile 65535"}, "msg": "line replaced"} > <127.0.0.1> REMOTE_MODULE lineinfile dest=/etc/security/limits.conf > regexp= insertafter=EOF line="root hard nofile 65535" > changed: [machine] => (item={'key': '', 'value': 'root hard nofile > 65535'}) => {"backup": "", "changed": true, "item": {"key": "", "value": > "root hard nofile 65535"}, "msg": "line replaced"} > <127.0.0.1> REMOTE_MODULE lineinfile dest=/etc/security/limits.conf > regexp= insertafter=EOF line="root soft memlock unlimited" > changed: [machine] => (item={'key': '', 'value': 'root soft memlock > unlimited'}) => {"backup": "", "changed": true, "item": {"key": "", > "value": "root soft memlock unlimited"}, "msg": "line replaced"} > <127.0.0.1> REMOTE_MODULE lineinfile dest=/etc/security/limits.conf > regexp= insertafter=EOF line="root hard memlock unlimited" > changed: [machine] => (item={'key': '', 'value': 'root hard memlock > unlimited'}) => {"backup": "", "changed": true, "item": {"key": "", > "value": "root hard memlock unlimited"}, "msg": "line replaced"} > > -- > 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/b2674cc4-01a9-4b1b-ab54-6a6acdb1097a%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/b2674cc4-01a9-4b1b-ab54-6a6acdb1097a%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > -- > 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/etPan.532c2e89.2ae8944a.11a12%40mobiletuvix.rackspace.corp<https://groups.google.com/d/msgid/ansible-project/etPan.532c2e89.2ae8944a.11a12%40mobiletuvix.rackspace.corp?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- 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/CAEVJ8QO90ntorLMs9rb0qNvoFG%2BDsPmrcfTKtdFmrfReWzCW4w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
