Exemplo n.º 1
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        if utils.get_deployment_user() != parsed_args.deployment_user:
            self.log.warning(
                _('The --deployment-user value %s does not '
                  'match the user name executing this command!') %
                parsed_args.deployment_user)

        ansible.write_default_ansible_cfg(parsed_args.output_dir,
                                          parsed_args.deployment_user,
                                          ssh_private_key=None)
Exemplo n.º 2
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)" % parsed_args)
        if utils.get_deployment_user() != parsed_args.deployment_user:
            self.log.warning(
                _('The --deployment-user value %s does not '
                  'match the user name executing this command!') %
                parsed_args.deployment_user)

        # FIXME(bogdando): unhardcode key/transport for future multi-node
        ansible.write_default_ansible_cfg(parsed_args.output_dir,
                                          parsed_args.deployment_user,
                                          ssh_private_key=None,
                                          transport='local')
Exemplo n.º 3
0
    def test_override_ansible_cfg(self):
        with tempfile.NamedTemporaryFile() as ansible_cfg_file:
            ansible_cfg_path = ansible_cfg_file.name
            work_dir = tempfile.mkdtemp(prefix='ansible-mistral-action-test')
            # Needed for the configparser to be able to read this file.
            ansible_cfg_file.write(b'[defaults]\n')
            ansible_cfg_file.write(b'[ssh_connection]\n')
            ansible_cfg_file.flush()

            override_ansible_cfg = (
                "[defaults]\n"
                "forks=10\n"
                "[ssh_connection]\n"
                "custom_option=custom_value\n"
            )

            resulting_ansible_config = ansible.write_default_ansible_cfg(
                work_dir, None, None, None, base_ansible_cfg=ansible_cfg_path,
                override_ansible_cfg=override_ansible_cfg)

            ansible_cfg = configparser.ConfigParser()
            ansible_cfg.read(resulting_ansible_config)

            self.assertEqual('10', ansible_cfg.get('defaults', 'forks'))
            self.assertEqual('custom_value',
                             ansible_cfg.get('ssh_connection',
                                             'custom_option'))
Exemplo n.º 4
0
    def test_override_ansible_cfg(self):
        with tempfile.NamedTemporaryFile() as ansible_cfg_file:
            ansible_cfg_path = ansible_cfg_file.name
            work_dir = tempfile.mkdtemp(prefix='ansible-mistral-action-test')
            # Needed for the configparser to be able to read this file.
            ansible_cfg_file.write(b'[defaults]\n')
            ansible_cfg_file.write(b'[ssh_connection]\n')
            ansible_cfg_file.flush()

            override_ansible_cfg = (
                "[defaults]\n"
                "forks=10\n"
                "[ssh_connection]\n"
                "custom_option=custom_value\n"
            )

            resulting_ansible_config = ansible.write_default_ansible_cfg(
                work_dir, None, None, None, base_ansible_cfg=ansible_cfg_path,
                override_ansible_cfg=override_ansible_cfg)

            ansible_cfg = configparser.ConfigParser()
            ansible_cfg.read(resulting_ansible_config)

            self.assertEqual('10', ansible_cfg.get('defaults', 'forks'))
            self.assertEqual('custom_value',
                             ansible_cfg.get('ssh_connection',
                                             'custom_option'))
Exemplo n.º 5
0
    def test_copy_config_file(self):
        with tempfile.NamedTemporaryFile() as ansible_cfg_file:
            ansible_cfg_path = ansible_cfg_file.name
            work_dir = tempfile.mkdtemp(prefix='ansible-mistral-action-test')
            # Needed for the configparser to be able to read this file.
            ansible_cfg_file.write(b'[defaults]\n')
            ansible_cfg_file.flush()

            resulting_ansible_config = ansible.write_default_ansible_cfg(
                work_dir, base_ansible_cfg=ansible_cfg_path)

            self.assertEqual(resulting_ansible_config,
                             os.path.join(work_dir, 'ansible.cfg'))

        config = configparser.ConfigParser()
        config.read(resulting_ansible_config)

        retry_files_enabled = config.get('defaults', 'retry_files_enabled')
        self.assertEqual(retry_files_enabled, 'False')
Exemplo n.º 6
0
    def test_copy_config_file(self):
        with tempfile.NamedTemporaryFile() as ansible_cfg_file:
            ansible_cfg_path = ansible_cfg_file.name
            work_dir = tempfile.mkdtemp(prefix='ansible-mistral-action-test')
            # Needed for the configparser to be able to read this file.
            ansible_cfg_file.write(b'[defaults]\n')
            ansible_cfg_file.flush()

            resulting_ansible_config = ansible.write_default_ansible_cfg(
                work_dir, base_ansible_cfg=ansible_cfg_path)

            self.assertEqual(resulting_ansible_config,
                             os.path.join(work_dir, 'ansible.cfg'))

        config = configparser.ConfigParser()
        config.read(resulting_ansible_config)

        retry_files_enabled = config.get('defaults', 'retry_files_enabled')
        self.assertEqual(retry_files_enabled, 'False')
Exemplo n.º 7
0
    def test_override_ansible_cfg_empty(self, cpu_count):
        with tempfile.NamedTemporaryFile() as ansible_cfg_file:
            ansible_cfg_path = ansible_cfg_file.name
            work_dir = tempfile.mkdtemp(prefix='ansible-mistral-action-test')
            # Needed for the configparser to be able to read this file.
            ansible_cfg_file.write(b'[defaults]\n')
            ansible_cfg_file.write(b'[ssh_connection]\n')
            ansible_cfg_file.flush()
            cpu_count.return_value = 4
            override_ansible_cfg = ""

            resulting_ansible_config = ansible.write_default_ansible_cfg(
                work_dir,
                None,
                None,
                None,
                base_ansible_cfg=ansible_cfg_path,
                override_ansible_cfg=override_ansible_cfg)

            ansible_cfg = configparser.ConfigParser()
            ansible_cfg.read(resulting_ansible_config)

            self.assertEqual('40', ansible_cfg.get('defaults', 'forks'))
Exemplo n.º 8
0
import sys
import shutil
from pathlib import Path
from six.moves import configparser
from tripleo_common.actions import ansible

output_dir = '/home/stack/config-download'
ansible_cfg = 'ansible.cfg'
deployment_user = '******'
ssh_private_key = '/home/stack/.ssh/id_rsa'

fact_caching_connection = '/tmp/ansible_fact_cache'

print ("Starting {} export...".format(ansible_cfg))

ansible.write_default_ansible_cfg(output_dir, deployment_user,
                                  ssh_private_key)

ansible_config_path = os.path.join(output_dir, ansible_cfg)
config = configparser.ConfigParser()
config.read(ansible_config_path)
config.set('defaults', 'fact_caching_connection',
           fact_caching_connection)
config.set('defaults', 'host_key_checking', 'false')

with open(ansible_config_path, 'w') as configfile:
    config.write(configfile)

dirpath = Path(fact_caching_connection)
if dirpath.exists() and dirpath.is_dir():
    shutil.rmtree(dirpath)