Hi,
try use handler:
- stat: path=/mnt/mysql
register: p
- name: Create /mnt/mysql directory for database
file:
path: /mnt/mysql
state: directory
mode: 0750
owner: mysql
group: mysql
when: not p.stat.exists
notify:
- create database
handlers:
- name: create database
command: mysql_install_db --user=mysql --datadir=/mnt/mysql
First time, there will not be /mnt/mysql, so we will create it in second
task. It has changed state, therefore we will call handler and create a
database. To be sure, we will skip it every time, the path already exists.
David Karban
Linux server specialist/Specialista na správu linuxových serverů
www.karban.eu
2016-02-02 4:04 GMT+01:00 Colin Byrne <[email protected]>:
> Hey, so I have the following sequence where I first register a variable,
> then want to evaluate stats from it later but I want the stats from when
> the variable was first created. What is the best way to do this?
>
> I could see registering a second variable immedeatly that evaulates
> properties of the variable that was just registered, but it doesn't seem
> too 'clean' of a method.
>
> What I am trying to do here is register a variable about a directory path,
> and only 'mysql_install_db' if that directory doesn't exist. However, I
> have to create that directory at some point, so by the time I run
> 'mysql_install_db' that 'p.stat.isdir' will evaluate to true every time,
> even if it didn't exist a second ago. So I somehow need to define and cache
> a variable one step ahead.
>
>
> - stat: path=/mnt/mysql
> register: p
>
>
> - name: Create /mnt/mysql directory for database
> file:
> path: /mnt/mysql
> state: directory
> mode: 0750
> owner: mysql
> group: mysql
>
>
> - name: Install mysql database in atypical datadir
>
> command: mysql_install_db --user=mysql --datadir=/mnt/mysql
> when: p.stat.isdir is defined and p.stat.isdir == False
>
> Thanks for any help. It is greatly appriciated!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/51f9f6d4-bf57-471b-bfdc-c414bcfa310e%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/51f9f6d4-bf57-471b-bfdc-c414bcfa310e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAOBFM95_8r3VzD%3D%3DboTEF8HZRRQjq6T-WeF1TB6bwtxROf3mHg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.