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
31 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,490 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
23 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,810 points
50 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,490 points
21 views