def _hide_sensitive_values(self, result):

        display = Display()

        me = os.path.basename(sys.argv[0])
        target = me.split('-')
        sub = target[1]
        myclass = "%sCLI" % sub.capitalize()
        mycli = getattr(__import__("ansible.cli.%s" % sub, fromlist=[myclass]),
                        myclass)

        try:
            args = [to_text(a, errors='surrogate_or_strict') for a in sys.argv]
        except UnicodeError:
            display.error(
                'Command line args are not in utf-8, unable to continue.  Ansible currently only understands utf-8'
            )
            display.display(u"The full traceback was:\n\n%s" %
                            to_text(traceback.format_exc()))
            exit_code = 6

        cli = mycli(args)
        cli.parse()

        # Get vault_password_file from CLI
        if len(cli.options.vault_password_files) != 0:
            self.vault_password_file = cli.options.vault_password_files[0]
        # Get vault_password_file from ansible.cfg
        else:
            self.vault_password_file = self.get_option('vault_password_file')

        for encrypted_vars_file in self.encrypted_vars_files_list:
            vars_file_decrypted = subprocess.check_output(
                [
                    "ansible-vault", "view", encrypted_vars_file,
                    "--vault-password-file", self.vault_password_file
                ],
                universal_newlines=True)

            sensitive_values_dict = yaml.safe_load(vars_file_decrypted)

            for v in sensitive_values_dict:
                CallbackModule.SENSITIVE_VALUES.add(sensitive_values_dict[v])

        self.check_sensitive_values(result._result)
Exemple #2
0
class Config(object):
    def __init__(self, configfile):
        self.display = Display()
        self.configfile = configfile
        self.logfile = None
        self.loglevel = None

    @property
    def parse_configfile(self):
        """
        Retrieve configuration parameters from the config file
        """
        try:
            with open(self.configfile, "r") as f:
                config = yaml.load(f)
        except:
            self.display.error("Can't read configuration file %s" %
                               self.configfile)
            sys.exit(1)
        return config
Exemple #3
0
class Config(object):

    def __init__(self, configfile):
        self.display = Display()
        self.configfile = configfile
        self.logfile = None
        self.loglevel = None

    @property
    def parse_configfile(self):
        """
        Retrieve configuration parameters from the config file
        """
        try:
            with open(self.configfile, "r") as f:
                config = yaml.load(f)
        except:
            self.display.error(
                "Can't read configuration file %s" % self.configfile
            )
            sys.exit(1)
        return config
Exemple #4
0
from ansible.utils.display import Display

display = Display()
os_logger = logging.getLogger("openstack")

try:
    # Due to the name shadowing we should import other way
    import importlib

    sdk = importlib.import_module("openstack")
    sdk_inventory = importlib.import_module("openstack.cloud.inventory")
    client_config = importlib.import_module("openstack.config.loader")
    sdk_exceptions = importlib.import_module("openstack.exceptions")
except ImportError:
    error_msg = "Couldn't import Openstack SDK modules"
    display.error(error_msg)
    raise AnsibleParserError(error_msg)


class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
    """ Host inventory provider for ansible using OpenStack clouds. """

    NAME = "openstack-inventory"

    def parse(self, inventory, loader, path, cache=True):

        super(InventoryModule, self).parse(inventory, loader, path)

        self._load_and_verify_plugin_config(path)

        hosts_data = None
Exemple #5
0
class Config(object):
    def __init__(self, configfile):
        self.display = Display()
        self.configfile = configfile
        self.logfile = None
        self.loglevel = None

    @property
    def parse_configfile(self):
        """
        Retrieve configuration parameters from the config file
        """
        try:
            with open(self.configfile, "r") as f:
                config = yaml.load(f)
        except:
            self.display.error("Can't read configuration file %s" %
                               self.configfile)
            sys.exit(1)
        return config

    def default_values(self, args, config):
        # Set kubespray_path
        if 'kubespray_path' not in config.keys(
        ) and args.kubespray_path is None:
            config['kubespray_path'] = os.path.join(os.path.expanduser("~"),
                                                    '.kubespray')
        arguments = dict(args._get_kwargs())
        for key, value in arguments.items():
            if value is not None:
                config[key] = value
        # Set inventory_path
        if 'inventory_path' not in config.keys(
        ) and args.inventory_path is None:
            config['inventory_path'] = os.path.join(config['kubespray_path'],
                                                    'inventory/inventory.cfg')
        # Set logfile
        if 'logfile' not in config.keys():
            config['logfile'] = os.path.join(config['kubespray_path'],
                                             'kubespray.log')
        # Set default bool
        for v in ['use_private_ip', 'assign_public_ip']:
            if v not in config.keys():
                config[v] = False
        # Set default instances type
        if args.func.__name__ == "aws":
            if 'masters_instance_type' not in config.keys(
            ) and args.masters_instance_type is None:
                config['masters_instance_type'] = 't2.medium'
            if 'nodes_instance_type' not in config.keys(
            ) and args.nodes_instance_type is None:
                config['nodes_instance_type'] = 't2.large'
            if 'etcds_instance_type' not in config.keys(
            ) and args.etcds_instance_type is None:
                config['etcds_instance_type'] = 't2.small'
        # ----GCE
        if args.func.__name__ == "gce":
            if 'masters_machine_type' not in config.keys(
            ) and args.masters_machine_type is None:
                config['masters_machine_type'] = 'n1-standard-2'
            if 'nodes_machine_type' not in config.keys(
            ) and args.nodes_machine_type is None:
                config['nodes_machine_type'] = 'n1-standard-4'
            if 'etcds_machine_type' not in config.keys(
            ) and args.etcds_machine_type is None:
                config['etcds_machine_type'] = 'n1-standard-1'
        # Conflicting options
        if args.func.__name__ == "aws":
            if args.security_group_name and 'security_group_id' in config.keys(
            ):
                config.pop('security_group_id')
            elif args.security_group_id and 'security_group_name' in config.keys(
            ):
                config.pop('security_group_name')
        # Set kubernetes 'kube' password
        if 'prompt_pwd' in config.keys() and config['prompt_pwd'] is True:
            pwd = read_password()
            config['k8s_passwd'] = pwd
        return (config)
Exemple #6
0
class Config(object):

    def __init__(self, configfile):
        self.display = Display()
        self.configfile = configfile
        self.logfile = None
        self.loglevel = None

    @property
    def parse_configfile(self):
        """
        Retrieve configuration parameters from the config file
        """
        try:
            with open(self.configfile, "r") as f:
                config = yaml.load(f)
        except:
            self.display.error(
                "Can't read configuration file %s" % self.configfile
            )
            sys.exit(1)
        return config

    def default_values(self, args, config):
        # Set kubespray_path
        if 'kubespray_path' not in config.keys() and args.kubespray_path is None:
            config['kubespray_path'] = os.path.join(os.path.expanduser("~"), '.kubespray')
        arguments = dict(args._get_kwargs())
        for key, value in arguments.items():
            if value is not None:
                config[key] = value
        # Set inventory_path
        if 'inventory_path' not in config.keys() and args.inventory_path is None:
            config['inventory_path'] = os.path.join(
                config['kubespray_path'], 'inventory/inventory.cfg'
            )
        # Set logfile
        if 'logfile' not in config.keys():
            config['logfile'] = os.path.join(config['kubespray_path'], 'kubespray.log')
        # Set default bool
        for v in ['use_private_ip', 'assign_public_ip']:
            if v not in config.keys():
                config[v] = False
        # Set default instances type
        if args.func.__name__ == "aws":
            if 'masters_instance_type' not in config.keys() and args.masters_instance_type is None:
                config['masters_instance_type'] = 't2.medium'
            if 'nodes_instance_type' not in config.keys() and args.nodes_instance_type is None:
                config['nodes_instance_type'] = 't2.large'
            if 'etcds_instance_type' not in config.keys() and args.etcds_instance_type is None:
                config['etcds_instance_type'] = 't2.small'
        # ----GCE
        if args.func.__name__ == "gce":
            if 'masters_machine_type' not in config.keys() and args.masters_machine_type is None:
                config['masters_machine_type'] = 'n1-standard-2'
            if 'nodes_machine_type' not in config.keys() and args.nodes_machine_type is None:
                config['nodes_machine_type'] = 'n1-standard-4'
            if 'etcds_machine_type' not in config.keys() and args.etcds_machine_type is None:
                config['etcds_machine_type'] = 'n1-standard-1'
        # Conflicting options
        if args.func.__name__ == "aws":
            if args.security_group_name and 'security_group_id' in config.keys():
                config.pop('security_group_id')
            elif args.security_group_id and 'security_group_name' in config.keys():
                config.pop('security_group_name')
        # Set kubernetes 'kube' password
        if 'prompt_pwd' in config.keys() and config['prompt_pwd'] is True:
            pwd = read_password()
            config['k8s_passwd'] = pwd
        return(config)