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

The role fails when conditionally included #105

Closed
BboyKeen opened this issue Jan 6, 2017 · 4 comments
Closed

The role fails when conditionally included #105

BboyKeen opened this issue Jan 6, 2017 · 4 comments
Assignees
Labels

Comments

@BboyKeen
Copy link

BboyKeen commented Jan 6, 2017

Hi,

I need to use your role only on specific environments so I'm using a when instruction in my role statement in my playbook like below to choose whether or not I want to deploy security rules :

roles: 
    - { role: security, when: deploy_security_rules }

Then in the task file of my "security" role I use the statements below to include your role

- name: OS Security related configurations
  include_role:
    name: dev-sec.os-hardening

The problem occurs when I don't want to deploy security rules, i.e when deploy_security_rules = false

Here is the output I obtain during failure :

TASK [dev-sec.os-hardening : get all system accounts] **************************
[DEPRECATION WARNING]: always_run is deprecated. Use check_mode = no instead..

This feature will be removed in version 2.4. Deprecation warnings can be 
disabled by setting deprecation_warnings=False in ansible.cfg.
skipping: [vagrant-debian8.6] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}

TASK [dev-sec.os-hardening : remove always ignored system accounts from list] **
skipping: [vagrant-debian8.6] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}

TASK [dev-sec.os-hardening : change system accounts not on the user provided ignore-list] ***
fatal: [vagrant-debian8.6]: FAILED! => {"failed": true, "msg": "'sys_accs_cond' is undefined"}

Any idea why the role is failing ?

rndmh3ro pushed a commit that referenced this issue Jan 6, 2017
omit empty variables when in check-mode or when set_fact is skipped.

Fix #105
@rndmh3ro
Copy link
Member

rndmh3ro commented Jan 6, 2017

Thanks for reporting!
That's happening because in Ansible 2.x undefined variables used in with_items loops cause an error, even if the task is skipped (e.g. in check_mode or like in your case). The variable is undefined because the previous task (remove always ignored system accounts from list) is skipped.

Should be fixed here: #106

@rndmh3ro rndmh3ro added the bug label Jan 6, 2017
@rndmh3ro rndmh3ro self-assigned this Jan 6, 2017
@rndmh3ro
Copy link
Member

rndmh3ro commented Jan 6, 2017

This also fixes #103

@BboyKeen
Copy link
Author

BboyKeen commented Jan 8, 2017

Thanks. I will try your fix and get back to you !

@BboyKeen
Copy link
Author

I can confirm that the fix proposed in the PR #106 solves the issue

rndmh3ro pushed a commit that referenced this issue Mar 1, 2017
omit empty variables when in check-mode or when set_fact is skipped.

Fix #105
rndmh3ro added a commit that referenced this issue Jul 24, 2020
divialth pushed a commit to divialth/ansible-collection-hardening that referenced this issue Aug 3, 2022
omit empty variables when in check-mode or when set_fact is skipped.

Fix dev-sec#105
divialth pushed a commit to divialth/ansible-collection-hardening that referenced this issue Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants