Needs to Write a Playbook

Hi Friends,

I am new to this Ansible world

Needs to write a playbook for one scenario

Scenario-1:

I have 1000 Servers . Host-names are like Server1, Server2, Server3, Server4, Server5, …Server1000 .

I have two Script files Script-1.sh and Script-2.sh in my controller .

Now i want create a folder “/opt/Server/Odd” and copy the Script-1.sh file in Server1, Server3, Server5, Server7 …Server999 .
create a folder “/opt/Server/Even” and copy the Script-2.sh file in Server2, Server4, Server6, Server8, …Server1000.

Can you guys help me to write playbook

Thanks in Advance

Hi Rama,

What have you tried and what is error that you are getting?

Hi Rama,

You can create playbook/role simples:

  1. create regex and split server from number “{{ ansible_hostname.split(‘server’)[1] }}”
  2. Check if the number is divisor per 2; {{ variable_number % 2 }}
  3. if divisor 2, copy script1 else copy script 2 file: src: script{{ var01 }}