Correction to my previous email:
You *COULD* run a play right before it that registers the full path of
`systemctl` found on the system (maybe use `shell: which systemctl`), but
that is not a stable method in some cases. I suggest using `systemd:` with
the OS version check if needed.
On Fri, Nov 16, 2018 at 9:31 PM <[email protected]> wrote:
> I'd suggest not using the `shell:` module, instead use the `systemd:`
> module.
>
> Then setup the `when:` clause with a third that only executes this play on
> OS versions that have `systemctl` (e.g. RHEL 7+, etc). You run a play
> right before it that registers the full path of `systemctl` found on the
> system (maybe use `shell: which systemctl`).
>
> Something like this:
> - name: manage services using systemctl
> tags: manage services using systemctl
> systemd:
> name: {{servicesList}}
> state: {{actionTodo}}
> with_items:
> - "{{servicesList}}"
> when:
> - ansible_os_family == "RedHat" and ansible_lsb.major_release|int
> >= 7
> - actionTodo != ""
> - servicesList != ""
> ignore_errors: true
> register: p2
>
>
> On Friday, November 16, 2018 at 8:06:40 AM UTC-6, [email protected]
> wrote:
>>
>> i'm trying this in a playbook:
>>
>> ..
>> vars:
>> actionTodo: "{{ variable_actionTodo }}"
>> servicesList: "{{ variable_servicesList }}"
>> actionTodo_list: [start,stop,rstart,rstop,status,rstatus]
>> ..
>>
>> - name: manage services using systemctl
>> tags: manage services using systemctl
>> shell: systemctl {{actionTodo}} {{servicesList}}
>> with_items:
>> - "{{servicesList}}"
>> when: actionTodo != "" and servicesList != ""
>> ignore_errors: true
>> register: p2
>>
>>
>> - debug:
>> var: p2
>>
>> i'd like to compare:
>> - actionTo value with value from actionTo_list
>> - and avoid printing "command not found" node without systemctl
>>
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/JLS67ALa3AU/unsubscribe.
> To unsubscribe from this group and all its topics, 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/b662b375-3856-4da9-8af4-c449285db436%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/b662b375-3856-4da9-8af4-c449285db436%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
***************** ************* *********** ******* ***** *** **
"If you wish to make an apple pie from scratch,
you must first invent the universe."
-- Carl Sagan
"Quis custodiet ipsos custodes?"
(Who can watch the watchmen?)
-- from the Satires of Juvenal
"I do not fear computers, I fear the lack of them."
-- Isaac Asimov (Author)
** *** ***** ******* *********** ************* *****************
--
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/CAGYusaNHuQc%2B7DoL6_7-MFk1uf_ZRvhePwnLX%3DAoGLjCpK9H2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.