User Tools

Site Tools


ansible:ansible_sandbox

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ansible:ansible_sandbox [2025/02/23 21:48]
manu [Test 3 backup file]
ansible:ansible_sandbox [2025/05/28 10:28] (current)
manu [Test 4 insertafter using bash]
Line 296: Line 296:
 ===== Test 3 backup file ===== ===== Test 3 backup file =====
  
 +
 +        ​
 File is backuped with format **2025-02-23T14:​30:​00Z** File is backuped with format **2025-02-23T14:​30:​00Z**
 <cli prompt='#'>​ <cli prompt='#'>​
Line 351: Line 353:
         - (backup_stat.stat.exists == false or current_checksum.stdout != backup_checksum.stdout)         - (backup_stat.stat.exists == false or current_checksum.stdout != backup_checksum.stdout)
 </​cli>​ </​cli>​
 +
 +===== Test 4 insertafter using bash =====
 +
 +<cli>
 +---
 +- name: Insert line after pattern using bash
 +  hosts: all
 +  become: true
 +  tasks:
 +    - name: Insert line after pattern using sed
 +      shell: |
 +        if ! grep -q '​^new_config_line=value$'​ /​etc/​example.conf;​ then
 +          sed -i '/# INSERT HERE/a new_config_line=value'​ /​etc/​example.conf
 +        fi
 +      args:
 +        executable: /bin/bash
 +</​cli> ​       ​
 +
 +https://​stackoverflow.com/​questions/​70162334/​in-ansible-how-do-i-add-a-line-without-delete-comment
 +
 +https://​www.theunixschool.com/​2012/​06/​insert-line-before-or-after-pattern.html
 +
 +
ansible/ansible_sandbox.1740343720.txt.gz · Last modified: 2025/02/23 21:48 by manu