0

I am trying to create a playbook that will see if "/etc/vmware-tools/services.sh" is running if not running then start.

I have tried command and shell but I can't figure the syntax for a conditional.

    --- # VMWARE_TOOLS_NOT_RUNNING
- hosts: redhat-vm-guest
  user: ansible-user
  become: true
  become_user: root
  connection: ssh
  gather_facts: false
  tasks:
  - name: check vmware tools is running
    command: /etc/vmware-tools/services.sh status
    register: status
  - name: print status
    debug:
      msg: "{{ status.stdout }}

2 Answers2

0

Use the following:

- name: check vmware tools is running
  command: /etc/vmware-tools/services.sh status
  register: _status
  ignore_errors: True

- name: Start VMWare Tools
    command: /etc/vmware-tools/services.sh start
  when: _status.stdout.find("running") == -1

I recommend using the service module if possible.

imjoseangel
  • 3,543
  • 3
  • 22
  • 30
0

I finally have something that works.

    --- # VMWARE_TOOLS_NOT_RUNNING
- hosts: vmwaretools
  user: ansibleuser
  become: true
  become_user: root
  connection: ssh
  gather_facts: false
  tasks:
  - name: vmware tools status
    command: /etc/vmware-tools/services.sh status
    ignore_errors: yes
    register: _status
  - debug: msg="{{ _status.stdout }}"
  - name: start vmware tools
    command: "/etc/vmware-tools/services.sh start"
    ignore_errors: yes
    when: _status == _status
  - debug: msg="{{ _status.stdout }}"