On 15/10/2021 13:37, dulhaver via Ansible Project wrote:
On 10/15/2021 1:01 PM Stefan Hornburg (Racke) <ra...@linuxia.de> wrote: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-checkWhat is the diagnosis of the syntax check?###################################################################### play -v --limit [host] postgres_install.yml --syntax-check Using /path/to/ansible.cfg as config file ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each: JSON: Expecting value: line 1 column 1 (char 0) Syntax Error while loading YAML. did not find expected key The error appears to be in '/home/gwagner/repos/ansible/step/step_server_env/postgres_install_test_external.yml': line 130, column 4, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: - service_facts: ^ here ######################################################################
Could be an indentation problem. Regards Racke
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'ok, thx. I'll play with that
-- 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/6947c99f-172d-bf50-7213-c6d7ae6ddb45%40linuxia.de.
OpenPGP_0x5B93015BFA2720F8.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature