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

0 votes

I have been trying to integrate the below stated command into a salt state:

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

but I want them to integrate only when either /data/mysql is empty or mysql contains no databases.

Can anyone help me with the above query please?

Thanks.

Jun 7, 2018 in DevOps Tools by Atul
• 10,200 points
28 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 should consider using this inside your state file to validate the existence of a path:

mysql_install_db:
  cmd.run: 
    - name: mysql_install_db --user=mysql --basedir=/usr/ --ldata=/data/mysql/
    - unless: file.path_exists_glob('/data/mysql/*')
If still issue persist then probably, the previous version of the state has some issues. Update the state based and it will resolve your issue. 
 
answered Jun 12, 2018 by Damon Salvatore
• 5,270 points

Related Questions In DevOps Tools

+1 vote
2 answers

Trying to make a PHP code work in bluemix

example to @Nilesh's explanation: $html = '<html> ...READ MORE

answered Oct 25, 2018 in DevOps Tools by akaash
17 views
0 votes
1 answer
0 votes
3 answers
0 votes
1 answer
+13 votes
2 answers
0 votes
1 answer

Using conditional to execute a command in salt

You can use unless inside your state ...READ MORE

answered Jul 23, 2018 in Other DevOps Questions by DareDev
• 6,560 points
37 views
0 votes
1 answer
0 votes
1 answer

How do I manage code that *removes* users in chef?

No, I don't think this will prove ...READ MORE

answered Aug 6, 2018 in DevOps Tools by Damon Salvatore
• 5,270 points
18 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.