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,380 points
87 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,810 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,280 points
44 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
• 41,660 points
637 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,280 points
55 views
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,380 points
180 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,510 points
40 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,810 points
382 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,810 points
48 views