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

ansible_service_mgr fact for sysvinit incorrect in ansible 2.4.0 #30753

Closed
toke opened this issue Sep 22, 2017 · 8 comments · Fixed by #31362 or #32086
Closed

ansible_service_mgr fact for sysvinit incorrect in ansible 2.4.0 #30753

toke opened this issue Sep 22, 2017 · 8 comments · Fixed by #31362 or #32086
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@toke
Copy link

toke commented Sep 22, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Ansible fact / variable ansible_service_mgr

ANSIBLE VERSION
ansible 2.4.0.0
CONFIGURATION

does not matter

OS / ENVIRONMENT

Target Debian Linux 7.11 (possible other Systems with sysvinit)

SUMMARY

Prior to ansible 2.4.0.0 ansible_service_mgr contained the value sysvinit, after the update to 2.4.0.0 ansible falls back to service. I would call it "alternative fact" right now, at least some roles fail due to this behaviour.

STEPS TO REPRODUCE

Outputting the fact ansible_service_mgr for a host running sysvinit (for example Debian 7.11 with sysvinit)

ansible -i host.example.com, -m setup  host.example.com | grep ansible_service_mgr
EXPECTED RESULTS
"ansible_service_mgr": "sysvinit",
ACTUAL RESULTS
"ansible_service_mgr": "service",
@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 22, 2017
@toke toke changed the title Ansible 2.4.0 breaks ansible_service_mgr fact Ansible 2.4.0 breaks ansible_service_mgr fact (sysvinit) Sep 22, 2017
@toke
Copy link
Author

toke commented Sep 22, 2017

Looking into https://github.com/ansible/ansible/blob/stable-2.4/lib/ansible/module_utils/facts/system/service_mgr.py I see several checks for comparison I'll did these by hand:

toke@desktop~$ ansible -i machine.example.com, -m setup machine.example.com |grep ansible_system
        "ansible_system": "Linux", 
        "ansible_system_vendor": "oVirt",
ssh toke@machine
toke@machine~$ ps -p 1 -o comm|tail -n 1
init
toke@machine:~$ cat /proc/1/comm
init
toke@machine:~$ [ -d /etc/init.d/ ] && echo "yes" 
yes

bcoca added a commit to bcoca/ansible that referenced this issue Sep 22, 2017
this allows for proper dependencies on facts already collected
fixes ansible#30753
fixes ansible#30623
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Sep 22, 2017
@alikins
Copy link
Contributor

alikins commented Sep 25, 2017

hmm, I was pretty sure this was related to ordering of collected facts (what #30777 addresses)
but now I wonder if service_mgr is just using the wrong fact names (without the 'ansible_' prefix)
(See devel...alikins:test_svc_mgr for a potential change
to fix)

alikins added a commit that referenced this issue Sep 28, 2017
* Fix fact failures cause by ordering of collectors

Some fact collectors need info collected by other facts.
(for ex, service_mgr needs to know 'ansible_system').
This info is passed to the Collector.collect method via
the 'collected_facts' info.

But, the order the fact collectors were running in is
not a set order, so collectors like service_mgr could
run before the PlatformFactCollect ('ansible_system', etc),
so the 'ansible_system' fact would not exist yet.

Depending on the collector and the deps, this can result
in incorrect behavior and wrong or missing facts.

To make the ordering of the collectors more consistent
and predictable, the code that builds that list is now
driven by the order of collectors in default_collectors.py,
and the rest of the code tries to preserve it.

* Flip the loops when building collector names

iterate over the ordered default_collectors list
selecting them for the final list in order instead
of driving it from the unordered collector_names set.

This lets the list returned by select_collector_classes
to stay in the same order as default_collectors.collectors

For collectors that have implicit deps on other fact collectors,
the default collectors can be ordered to include those early.

* default_collectors.py now uses a handful of sub lists of
collectors that can be ordered in default_collectors.collectors.

fixes #30753
fixes #30623

(cherry picked from commit 95abc1d)
@alikins
Copy link
Contributor

alikins commented Sep 28, 2017

fix was also cherry-picked to stable-2.4 in 4025b47
(from 95abc1d from #30777)

@alikins alikins changed the title Ansible 2.4.0 breaks ansible_service_mgr fact (sysvinit) ansible_service_mgr fact for sysvinit incorrect in ansible 2.4.0 Sep 29, 2017
prasadkatti pushed a commit to prasadkatti/ansible that referenced this issue Oct 1, 2017
* Fix fact failures cause by ordering of collectors

Some fact collectors need info collected by other facts.
(for ex, service_mgr needs to know 'ansible_system').
This info is passed to the Collector.collect method via
the 'collected_facts' info.

But, the order the fact collectors were running in is
not a set order, so collectors like service_mgr could
run before the PlatformFactCollect ('ansible_system', etc),
so the 'ansible_system' fact would not exist yet. 

Depending on the collector and the deps, this can result
in incorrect behavior and wrong or missing facts.

To make the ordering of the collectors more consistent
and predictable, the code that builds that list is now
driven by the order of collectors in default_collectors.py,
and the rest of the code tries to preserve it.

* Flip the loops when building collector names

iterate over the ordered default_collectors list
selecting them for the final list in order instead
of driving it from the unordered collector_names set.

This lets the list returned by select_collector_classes
to stay in the same order as default_collectors.collectors

For collectors that have implicit deps on other fact collectors,
the default collectors can be ordered to include those early.

* default_collectors.py now uses a handful of sub lists of
collectors that can be ordered in default_collectors.collectors.

fixes ansible#30753
fixes ansible#30623
BondAnthony pushed a commit to BondAnthony/ansible that referenced this issue Oct 5, 2017
* Fix fact failures cause by ordering of collectors

Some fact collectors need info collected by other facts.
(for ex, service_mgr needs to know 'ansible_system').
This info is passed to the Collector.collect method via
the 'collected_facts' info.

But, the order the fact collectors were running in is
not a set order, so collectors like service_mgr could
run before the PlatformFactCollect ('ansible_system', etc),
so the 'ansible_system' fact would not exist yet. 

Depending on the collector and the deps, this can result
in incorrect behavior and wrong or missing facts.

To make the ordering of the collectors more consistent
and predictable, the code that builds that list is now
driven by the order of collectors in default_collectors.py,
and the rest of the code tries to preserve it.

* Flip the loops when building collector names

iterate over the ordered default_collectors list
selecting them for the final list in order instead
of driving it from the unordered collector_names set.

This lets the list returned by select_collector_classes
to stay in the same order as default_collectors.collectors

For collectors that have implicit deps on other fact collectors,
the default collectors can be ordered to include those early.

* default_collectors.py now uses a handful of sub lists of
collectors that can be ordered in default_collectors.collectors.

fixes ansible#30753
fixes ansible#30623
interatom added a commit to wcm-io-devops/ansible-aem-cms that referenced this issue Oct 9, 2017
@toke
Copy link
Author

toke commented Oct 17, 2017

Not sure if the fixes should work by now but testing against devel or v2.4.1.0-0.3.rc1 I still get the value "service" for the fact "ansible_service_mgr".

@alikins Should this issue reopened?

@toke
Copy link
Author

toke commented Oct 17, 2017

I've put together a small vagrant test: https://gist.github.com/toke/d5de03c70c9c7f1a2ec6acd7a9e3753a

@toke
Copy link
Author

toke commented Oct 24, 2017

@alikins Thanks for your effort.
This fixes the issue. Let's hope it will make it in 2.4.1.

alikins added a commit that referenced this issue Oct 24, 2017
The platform/distro/etc facts were being passed in
correctly, but service_mgr.py was looking up the
wrong names ('system' vs 'ansible_system') resulting
in service_mgr falling back to default 'service' result.

Fixes #30753, #31095
abadger pushed a commit that referenced this issue Oct 26, 2017
The platform/distro/etc facts were being passed in
correctly, but service_mgr.py was looking up the
wrong names ('system' vs 'ansible_system') resulting
in service_mgr falling back to default 'service' result.

Fixes #30753, #31095
(cherry picked from commit 6203e89)
abadger pushed a commit that referenced this issue Oct 26, 2017
The platform/distro/etc facts were being passed in
correctly, but service_mgr.py was looking up the
wrong names ('system' vs 'ansible_system') resulting
in service_mgr falling back to default 'service' result.

Fixes #30753, #31095
(cherry picked from commit 6203e89)
@aabdnn
Copy link

aabdnn commented Oct 27, 2017

I've just tested 2.4.1, and it's still reporting "service" instead of "upstart" for CentOS 6

@abadger
Copy link
Contributor

abadger commented Oct 27, 2017 via email

alikins added a commit that referenced this issue Jan 22, 2018
Add deps/requires for fact collectors

Fact collectors can now set a required_facts
class attribute that will be a set of the names
of fact collectors they require to be run first.

ie, if a collector needs to know the ansible_distribution,
it should set it's required_facts to include 'distribution'

        required_facts = set(['distribution'])

If a collector requires another collector, it gets added
to the selected collector names.

We then topological sort the ordering of the collectors
so that deps work out (ie, 'distribution' will run before
'service_mgr')

required_facts were added to the collectors for:

        - network (requires 'distribution', 'platform')
        - hardware (requires 'platform')
        - service_mgr (requires 'distribution', 'platform')

Fix name references for facts (need 'ansible_' prefix)
is service_mgr

Fixes #30753
KAMI911 added a commit to KAMI911/ansible-role-wildfly that referenced this issue Jan 29, 2018
KAMI911 added a commit to KAMI911/ansible-role-wildfly that referenced this issue Jan 30, 2018
KAMI911 added a commit to KAMI911/ansible-role-wildfly that referenced this issue Jan 30, 2018
Lujeni pushed a commit to Lujeni/ansible that referenced this issue Feb 1, 2018
Add deps/requires for fact collectors

Fact collectors can now set a required_facts
class attribute that will be a set of the names
of fact collectors they require to be run first.

ie, if a collector needs to know the ansible_distribution,
it should set it's required_facts to include 'distribution'

        required_facts = set(['distribution'])

If a collector requires another collector, it gets added
to the selected collector names.

We then topological sort the ordering of the collectors
so that deps work out (ie, 'distribution' will run before
'service_mgr')

required_facts were added to the collectors for:

        - network (requires 'distribution', 'platform')
        - hardware (requires 'platform')
        - service_mgr (requires 'distribution', 'platform')

Fix name references for facts (need 'ansible_' prefix)
is service_mgr

Fixes ansible#30753
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
6 participants