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 13, 2018 in Ansible by Damon Salvatore
• 5,540 points
408 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 13, 2018 by DareDev
• 6,850 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 23 by vivek
• 510 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,250 points
4,274 views
0 votes
1 answer

Is it possible to run commands on ansible host?

If you just trying to run a ...READ MORE

answered Jan 9, 2019 in Ansible by Vijay
312 views
0 votes
1 answer
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,400 points
412 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,850 points
1,310 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,850 points
1,008 views