Reputation: 5916
I'm trying to backup Postgres DB by a pg_dump, but this can be done only if the service is running.
Example:
- name: Backup DB to Amazon S3
when: ansible_facts.services["postgresql.service"] is defined
become: no
shell: pg_dump -U postgres -d my_db -Z 9 | aws s3 cp --storage-class STANDARD_IA --sse aws:kms - s3://my_bucket/{{inventory_hostname}}/dump-`date +%Y-%m-%d-%H-%M-%S`.sql.gz
This checks that service if defined, how to check if the service is running?
Upvotes: 0
Views: 167
Reputation: 31
The ansible_facts.services module you are calling has a status variable. Have you tried this?
when: ansible_facts.services["postgresql.service"].state == started
Upvotes: 2