hi
can someone show me how to replicate below bash script into ansible-playbook.
#!/bin/sh
for NODE in server01 server02 server03 server04
do
grep -q $NODE file1
RETURN1=$?
grep -q $NODE file2
RETURN2=$?
if [ $RETURN1 -eq 1 ] && [ $RETURN2 -eq 1 ]
then
echo $NODE
fi
done
Hi,
Look, please, at example below:
- name: Multi if demo
hosts: all
gather_facts: false
vars:
file1: "server02 server03"
file2: "server03 server04"
tasks:
- name: Simple multi if demo
debug:
msg: "{{ inventory_hostname }}"
when:
- inventory_hostname in file1
- inventory_hostname in file2
Hi
It is a little bit more complicate:
- name: Multi if demo
hosts: all
gather_facts: false
vars:
file1s: "{{ lookup('file','file1') }}"
file2s: "{{ lookup('file','file2') }}"
tasks:
- name: Simple multi if demo
debug:
msg: "{{ inventory_hostname }}"
when:
- inventory_hostname in file1s
- inventory_hostname in file2s
Good luck.
Many Thanks Alex.
its works now.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.