Difference between revisions of "Register: (Ansible)"

From wikieduonline
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
 
   - name: [[Search string with lineinfile]]
 
   - name: [[Search string with lineinfile]]
 
     hosts: yourhost
 
     hosts: yourhost
 
+
 
     tasks:
 
     tasks:
 
       - name: "Searching for a String"
 
       - name: "Searching for a String"
Line 17: Line 17:
 
         become_user: root
 
         become_user: root
 
         register: ispresentvar
 
         register: ispresentvar
         shell: "[[grep -i]] 'YOUR_TEXT' /path/to/your/file.txt"
+
         [[shell:]] "[[grep -i]] 'YOUR_TEXT' /path/to/your/file.txt"
 
+
 
       - name: "sample task in case the String present in the file"
 
       - name: "sample task in case the String present in the file"
 
         debug: msg="INFO YOUR_TEXT is present in /path/to/your/file.txt"
 
         debug: msg="INFO YOUR_TEXT is present in /path/to/your/file.txt"

Latest revision as of 12:10, 8 September 2023

You can create variables from the output of an Ansible task with the task keyword.

If a task fails or is skipped, Ansible still registers a variable with a failure or skipped status, unless the task is skipped based on tags. See Tags for information on adding and using tags.


https://www.middlewareinventory.com/blog/ansible-search-string-file-check-if-string-exists/

 - name: Search string with lineinfile
   hosts: yourhost

   tasks:
     - name: "Searching for a String"
       become: yes
       become_user: root
       register: ispresentvar
       shell: "grep -i 'YOUR_TEXT' /path/to/your/file.txt"

     - name: "sample task in case the String present in the file"
       debug: msg="INFO YOUR_TEXT is present in /path/to/your/file.txt"
       when: ispresentvar is changed


Related terms[edit]

See also[edit]

Advertising: