Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service option must_exist disappeared #13259

Closed
Hubbitus opened this issue Nov 23, 2015 · 13 comments
Closed

Service option must_exist disappeared #13259

Hubbitus opened this issue Nov 23, 2015 · 13 comments
Assignees
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@Hubbitus
Copy link

Hubbitus commented Nov 23, 2015

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION

2.0.0-0.6.rc1

COMPONENT NAME

service_module

It was mentioned as became available in ansible 2.0 in doc: http://docs.ansible.com/ansible/service_module.html . It also was work as described.

In recent versions (2.0.0-0.6.rc1) it produce error:

fatal: [egais.db.slave1]: FAILED! => {"changed": false, "failed": true, "msg": "unsupported parameter for module: must_exist"}

And doc does not contain it.

Is that dropped? Why?

@bcoca bcoca self-assigned this Dec 7, 2015
@bcoca
Copy link
Member

bcoca commented Dec 7, 2015

I did this, need to look at my notes for exactly why, putting it in my queue to check once back home to review my notes

@peterhoeg
Copy link

There is a PR here ansible/ansible-modules-core#2816 which solves it. I'm manually applying the patch here.

@dailyherold
Copy link

@bcoca found this issue after following up on some old TODO's I had in my repo regarding must_exist. Any insight into what happened? Your time is much appreciated!

@yitzikc
Copy link

yitzikc commented May 31, 2016

I still have this issue as of 2.0.2, requiring an ugly workaround. Any suggestions as to how it can be expedited?

@ansibot ansibot added the affects_2.2 This issue/PR affects Ansible v2.2 label Sep 8, 2016
@ansibot ansibot added the affects_2.3 This issue/PR affects Ansible v2.3 label Dec 13, 2016
@bcoca
Copy link
Member

bcoca commented Feb 7, 2017

So this was a feature we attemtped to add in devel, but never released, I had to remove it as it seemed to break several existing plays and I never had time to look at the corner cases.

In any case there is easy existing workaround using failed_when:

@phemmer
Copy link
Contributor

phemmer commented Feb 8, 2017

I had a related ticket (#16134) that was closed (objectionably) as a duplicate of this one. So I'm copying the core for that ticket here:

The issue is that ansible throws an error when stopping/disabling an unknown service. The must_exist option would be able to fix this use case, but the behavior should be that it is automatically enabled, though only when stopping or disabling the service. Thereby restoring the behavior of ansible 1.9.4
Satisfaction of this requirement does not require a must_exist option. It could be resolved without implementing must_exist as the behavior would be automatic (hence why it is not a duplicate).

@ansibot
Copy link
Contributor

ansibot commented Apr 11, 2017

@Hubbitus Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:

  • issue type
  • ansible version
  • component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

@ansibot ansibot added needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. labels Apr 11, 2017
@Hubbitus
Copy link
Author

I had fill ansible version, issue type and component name.

@ansibot ansibot added module This issue/PR relates to a module. and removed needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. labels Jun 12, 2017
@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@Gunni
Copy link

Gunni commented Apr 5, 2018

this bug still active? the PR was pulled and i could not see an alternative, right now all disables of non-existant throw errors which i have to ignore

@sivel
Copy link
Member

sivel commented Apr 5, 2018

We have recently made the decision that we plan on leaving the behavior as is (failing when the service does not exist)

As discussed in #35293 the correct option here is to use either ignore_errors: true or a failed_when statement to prevent an error.

Logs of that meeting:
https://meetbot.fedoraproject.org/ansible-meeting/2018-01-25/ansible_core.2018-01-25-15.00.log.html

If you have further questions please stop by IRC or the mailing list:

@sivel sivel closed this as completed Apr 5, 2018
@Gunni
Copy link

Gunni commented Apr 5, 2018

So, you are saying that check mode should always say changed and non-check should always error for this.

That just feels very unpolished..

@Gunni
Copy link

Gunni commented Apr 5, 2018

I solved my case this way, this feels dumb but i'm limited by what you give me... And it's not portable to systems without systemd.

p.s. before you ask, i'm not running the machines naked, i already enabled nftables when this runs.

- name: Check if services exist
  command: "systemctl status {{item}}"
  check_mode: false
  changed_when: false
  failed_when: killable_services.rc not in [0, 3, 4]
  with_items:
  - firewalld
  - ip6tables
  - iptables
  register: killable_services

- name: Stop and disable services
  systemd:
    name: "{{item.item}}"
    state: stopped
    enabled: false
  with_items:
  - "{{killable_services.results}}"
  loop_control:
    label: "{{item.item}}"
  when:
  - item.rc != 4

@bcoca
Copy link
Member

bcoca commented Apr 5, 2018

much simpler:

- service:
  ...
  register: myres
  failed_when: myres is failed and not 'Could not find the requested service' in myres.msg

@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

9 participants