quick_test/Untitled-1.yml

28 lines
878 B
YAML

---
- name: Determine network interface name from IP address
hosts: localhost
tasks:
- name: Gather all facts
ansible.builtin.setup:
- name: Find the interface for a given IP address
set_fact:
interface_name: "{{ ansible_interfaces | map('regex_replace', '^', 'ansible_') | map('extract', ansible_facts) | selectattr('ipv4.address', 'equalto', '192.168.1.150') | map(attribute='device') | first }}"
- name: Display the interface name
debug:
msg: "The interface for IP address 192.168.1.150 is {{ interface_name }}"
---
- name: Count matches in a file
hosts: localhost
tasks:
- name: Search for the pattern in the file
shell: "grep -o 'pattern' /path/to/file | wc -l"
register: match_count
- name: Display the number of matches
debug:
msg: "Number of matches: {{ match_count.stdout }}"