Running ansible command on a single server when it is deployed to multiple servers

+1 vote
I want to run a database migration operation at the end of a deployment process for my application. So, the problem is I want to cal this operation only once for one particular server, but ansible runs all commands on all given servers. Is there any way to do this?
Jun 14, 2018 in Ansible by Damon Salvatore
• 5,980 points
2,483 views

2 answers to this question.

+2 votes

You can try the run_once attribute:

Example from the ansible docs:

---
# ...

  tasks:

    # ...

    - command: /opt/application/upgrade_db.py
      run_once: true

    # ...
answered Jun 14, 2018 by DareDev
• 6,890 points
+1 vote

Hi,

You may try to executive delegate_to module to the playbook hence the task will be executed in that particular server at once.

Example:

----
hosts: all
tasks:
  -name: Running ansible command on a single server
  command:
delegate_to: server name

answered Jan 24, 2020 by vivek
• 530 points

Related Questions In Ansible

0 votes
1 answer
+1 vote
3 answers
+1 vote
1 answer

Is it possible to append a large amount of text to a file using Ansible?

Here is concept which you can follow. blockinfile is ...READ MORE

answered Jul 30, 2018 in Ansible by Atul
• 10,240 points
14,746 views
+1 vote
1 answer
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,062 views
0 votes
1 answer

Using multiple config files using same template in a role in ansible

Go through this include_role module: tasks: - ...READ MORE

answered Jun 5, 2018 in Ansible by DareDev
• 6,890 points
4,244 views
0 votes
1 answer

Permission denied when running ansible playbook through jenkins

Jenkins uses it's own user to execute ...READ MORE

answered Jun 25, 2018 in Ansible by DareDev
• 6,890 points
4,167 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP