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,240 points
1,849 views

1 answer to this question.

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,980 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
824 views
0 votes
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,059 views
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,890 points
2,092 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,980 points
665 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