Difference between revisions of "Register: (Ansible)"

From wikieduonline
Jump to navigation Jump to search
Line 6: Line 6:
 
  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.
 
  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: youhost
 +
 +
    tasks:
 +
      - name: "Searching for a String"
 +
        become: yes
 +
        become_user: root
 +
        register: presence
 +
        shell: "grep -i 'LogLevel debug' /etc/httpd/conf/httpd.conf"
 +
 +
      - name: "sample task in case the String present in the file"
 +
        debug: msg="DEBUG is enabled in Apache Log file"
 +
        when: presence is changed
  
  

Revision as of 12:05, 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: youhost
   tasks:
     - name: "Searching for a String"
       become: yes
       become_user: root
       register: presence
       shell: "grep -i 'LogLevel debug' /etc/httpd/conf/httpd.conf"
     - name: "sample task in case the String present in the file"
       debug: msg="DEBUG is enabled in Apache Log file"
       when: presence is changed


Related terms

See also

Advertising: