On 15/10/2021 12:40, dulhaver via Ansible Project wrote:
On 10/15/2021 12:07 PM Stefan Hornburg (Racke) <ra...@linuxia.de> wrote:On 15/10/2021 12:04, dulhaver via Ansible Project wrote:On 10/15/2021 11:41 AM Stefan Hornburg (Racke) <ra...@linuxia.de> wrote:On 15/10/2021 11:20, dulhaver via Ansible Project wrote:I am trying to install postgresql via a playbook and want to make sure the service is not running prior installation on the target (rhel7/8 & debian10) machines. However my task below - name: stop postgresql.service from systemd if running service: name: postgresql.service state: stopped # enabled: false become: yes is failing ('Could not find the requested service postgresql.service: host') so, I guess I have to build something that directs the target to ignore that and continues with the playbook. I just can't see anythingYou can check the status of the postgresql service as follows: - service_facts: - debug: msg: "{{ ansible_facts.services.postgresql | default({ 'state' : 'absent'}) }}" TASK [service_facts] *************************************************************************************************************************************** ok: [papas] TASK [debug] *********************************************************************************************************************************************** ok: [papas] => { "msg": { "name": "postgresql", "source": "sysv", "state": "running" } }are those arguments to the the "service" module? how exaclty would I weave those into my task? I tried - name: stop postgresql.service from systemd if running service: name: postgresql service_facts: debug: msg: "{{ ansible_facts.services.postgresql | default({ 'state' : 'absent'}) }}" state: stopped # enabled: false become: yes but that did not workNo, use my tasks verbatim.hm ... pasting this verbatim to my plabook does not survice a --symtax-check
What is the diagnosis of the syntax check?
I figured out soome sort of sense-making output with adding 2 tasks based on what you posted. ############################################################ - name: gather service facts service_facts: - name: return postgres running or not debug: msg: "{{ ansible_facts.services.postgresql | default({ 'state' : 'absent'}) }}" ############################################################ however ... what do I do whith that output ('state: absent' in my test scenario)? Maybe I need to put this to work as some sort of condition deciding whether to run a 'service' task disabling the postgresql.service or not?
Correct. For example: when: ansible_facts.services.postgresql.state == 'running' Regards Racke -- Ecommerce and Linux consulting + Perl and web application programming. Debian and Sympa administration. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5ff305cb-bdbf-c335-4bd9-e77fbbfde318%40linuxia.de.
OpenPGP_0x5B93015BFA2720F8.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature