Difference between revisions of "Register: (Ansible)"
Jump to navigation
Jump to search
(4 intermediate revisions by 2 users not shown) | |||
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: 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 | ||
Line 12: | Line 28: | ||
* <code>[[when:]]</code> | * <code>[[when:]]</code> | ||
* <code>[[msg: The task includes an option with an undefined variable.]]</code> | * <code>[[msg: The task includes an option with an undefined variable.]]</code> | ||
+ | * [[Ansible state]], <code>[[state:]]</code> | ||
== See also == | == See also == |
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]
- Ansible modules:
gather_facts, set_fact
,ansible.builtin.file
,lineinfile
,stat
,group
,mount
,git:
,package:
,command:
,shell:
,raw:
,template:
,register:
,user:
, Ansible playbooks examples,tasks:
,lineinfile, blockinfile:
,shell:
,command:
,raw:
,ansible.builtin.file, service:, aws.ecs_taskdefinition, aws.asg, docker_container, kubernetes.core.k8s
,community.
,include_tasks
- Ansible: modules, plugins, Playbooks (examples)
ansible-playbook
,ansible-vault
,ansible-inventory
,ansible-config
, Ansible Tower, Ansible Galaxy (Roles) (ansible-galaxy
),ansible-cmdb
,gather facts
,ansible.cfg
,Ansible Molecule
, Ansible collections,register
,template
,--ask-pass
,--ask-become-pass
,remote_user:
,/etc/ansible/hosts
,ansible-doc
,ansible-lint
,.ansible/
,--forks
,--start-at-task
,changelog
,inventory
,Notify:
,ansible HOSTNAME -m ping
,gathering
,/usr/bin/ansible
,ansible -m ping
,ansible.builtin
,hosts: (Ansible)
,set fact:
,when:
,blockinfile:
,become method:
,include:
,git:
, AWX,ansible --help
, Tags, Ansible variables, versions
Advertising: