Skip to content

ansible: env vars set in vars plugin not present in play for localhost #297

@manicminer

Description

@manicminer

This might sound strange, and may even be an unexpected behavior of Ansible to begin with.

I have a vars plugin which sets some environment variables in-process. When I use the stock linear strategy, these vars are visible for plays running on localhost. When I use Mitogen, the vars are not visible.

Reproducing

# vars_plugins/test.py

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.plugins.vars import BaseVarsPlugin
import os

class VarsModule(BaseVarsPlugin):
    def __init__(self, *args):
        super(VarsModule, self).__init__(*args)
        os.environ['FOO'] = 'bar'

    def get_vars(self, loader, path, entities, cache=True):
        super(VarsModule, self).get_vars(loader, path, entities)
        return {}
---
# playbook.yml

- hosts: localhost
  strategy: linear
  connection: local
  tasks:
    - shell: "env | grep FOO"

- hosts: localhost
  connection: local
  tasks:
    - shell: "env | grep FOO"

I fully admit this is abuse of a vars plugin, but I use it to set context-specific AWS_* variables, so that the correct AWS account is chosen based on some runtime logic.

Look forward to any feedback on this scenario! Is this sane? Fixable in Mitogen or antithetical to Mitogen's design? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    ansibleIssues relating to Mitogen for AnsiblebugCode feature that hinders desired execution outcomeuser-reported

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions