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,360 points
37 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,560 points

Related Questions In Other DevOps Questions

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,040 points
31 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
• 35,800 points
157 views
0 votes
1 answer

Copy log files to local machines using Jenkins

Try initializing the variables with values according ...READ MORE

answered May 2, 2018 in Other DevOps Questions by ajs3033
• 7,040 points
34 views
+13 votes
2 answers
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,270 points
28 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,560 points
156 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,560 points
29 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.