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

run_once in a role combined with when in a playbook is erratic #13226

Closed
nneubauer opened this issue Nov 20, 2015 · 9 comments
Closed

run_once in a role combined with when in a playbook is erratic #13226

nneubauer opened this issue Nov 20, 2015 · 9 comments
Labels
affects_1.9 This issue/PR affects Ansible v1.9 bug This issue/PR relates to a bug. feature This issue/PR relates to a feature request. 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. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@nneubauer
Copy link

Issue Type: Bug Report

Ansible Version: 1.9.3

Ansible Configuration: Nothing special

Environment: Mac OS X 10.11

Summary:

A playbook that does apply a role under certain circumstances (using when) is created. Within the role a task is tagged with run_once. Now, it seems that run_once just selects the first host that was matched from the playbook. If that host however actually fails the when validation from the roles definition. The task is never run (skipped).

  roles:
  - {
    role: some-role,
    when: "'some_group' in group_names",
    sudo: yes,
    }
- name: Some Task
  template: src=some-file.j2 dest=/opt/some-file
  run_once: true

Steps To Reproduce:

Basically look at the above example. Make sure your hosts: definition matches at least two hosts and your when definition matches only a subset.

Expected Results:

I expect the task in the playbook to run_once on one of the hosts that actually are covered by the when statement from the playbook.

Actual Results:

Sometimes (depending on the order of your matched hosts), the task is not run at all but marked as skipped for one host that when does not match on.

@sivel
Copy link
Member

sivel commented Nov 20, 2015

run_once will run on the first host in the list of hosts in the play. Using a when statement that potentially limits based on host facts or groups could be expected to result in this behavior.

To ensure that it runs on a valid host, you could use 'delegate_to`

@nneubauer
Copy link
Author

Well, I get "what it does" to achieve what it promises, but for me it seems that the solution is not working. From a role's point of view I can not know from what kind of playbook I am run. I can certainly not use delegate_to because in my case I have no knowledge about the inventory. I had to solve it by adding a mandatory variable for the role containing the inventory_hostname that the specific run_once task should be run on.

@bcoca
Copy link
Member

bcoca commented Nov 21, 2015

what you are asking is for a 'run_once_successfully' which is not a current feature.

@ansibot
Copy link
Contributor

ansibot commented Apr 11, 2017

@nneubauer 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:

  • 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
@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@ansibotdev
Copy link

@nneubauer You have not responded to information requests in this issue so we will assume it no longer affects you. If you are still interested in this, please create a new issue with the requested information.

click here for bot help

@kmadnani
Copy link

this issue affects me too.

@ansibot ansibot added feature This issue/PR relates to a feature request. bug This issue/PR relates to a bug. and removed feature_idea labels Mar 2, 2018
@alexhexabeam
Copy link

For anyone finding this from google, here's one that's still open for this ticket. #23594

@stevanikof
Copy link

I solve this by putting the 'when' before the 'run_once'
This narrows the host list to a set I want to run once on

@Timoses
Copy link

Timoses commented Apr 2, 2019

I solve this by putting the 'when' before the 'run_once'
This narrows the host list to a set I want to run once on

This does not work.
Plus, I doubt that the order of keywords matters (it should not!)!

@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_1.9 This issue/PR affects Ansible v1.9 bug This issue/PR relates to a bug. feature This issue/PR relates to a feature request. 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. 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