Using conditional to execute a command in salt

0 votes

I am trying to run this command in a salt state:

mysql_install_db --user=mysql --basedir=/usr/ --ldata=/data/mysql/

But I want this to run only if the /data/mysql directory is empty i.e. there are no databases in it. Is there any conditional I can use here?

Jul 23, 2018 in Other DevOps Questions by DragonLord999
• 8,450 points
747 views

1 answer to this question.

0 votes

You can use unless inside your state file to verify the existence of path:

mysql_install_db:
  cmd.run: 
    - name: mysql_install_db --user=mysql --basedir=/usr/ --ldata=/data/mysql/
    - unless: file.path_exists_glob('/data/mysql/*')
answered Jul 23, 2018 by DareDev
• 6,890 points

Related Questions In Other DevOps Questions

0 votes
0 answers
0 votes
1 answer

Base a stage in pipeline by using a preloaded template

I don't think it's possible to load ...READ MORE

answered Jul 11, 2018 in Other DevOps Questions by ajs3033
• 7,280 points
217 views
0 votes
1 answer

How to stop sqlplus command in unix shell script when any sql fails

One idea would be to launch the ...READ MORE

answered Jul 16, 2018 in Other DevOps Questions by Kalgi
• 52,350 points
3,846 views
+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
1,761 views
0 votes
1 answer

Want a command to be executed in Salt only if a directory is empty

You should consider using this inside your ...READ MORE

answered Jun 12, 2018 in DevOps Tools by Damon Salvatore
• 5,980 points
689 views
0 votes
1 answer

How to get issues count based on rules in a sonar project?

There are API docs in the footer ...READ MORE

answered May 4, 2018 in Other DevOps Questions by DareDev
• 6,890 points
1,884 views
0 votes
1 answer

Salt: Require packages installed before executing a formula

You're on the right path. Using require_in ...READ MORE

answered Jul 13, 2018 in Other DevOps Questions by DareDev
• 6,890 points
648 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP