X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=descriptor-packages%2Ftools%2Fcharm-generator%2Fgenerator%2Fansible-charm%2Ftemplates%2Fansible_lib.py.j2;h=afbf162d5edb307e004d30b27315fd6f2f553599;hb=84fe31f632166d2fbf566968bd25aa9545e96fdc;hp=109bae05d55bbaa71abdd2e5cbbd669a460b7b8f;hpb=9aef1dc341d83b89cd81deab2fc87bdcd5f730fa;p=osm%2Fdevops.git diff --git a/descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/ansible_lib.py.j2 b/descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/ansible_lib.py.j2 index 109bae05..afbf162d 100644 --- a/descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/ansible_lib.py.j2 +++ b/descriptor-packages/tools/charm-generator/generator/ansible-charm/templates/ansible_lib.py.j2 @@ -49,6 +49,7 @@ def create_hosts(cfg, hosts): with open(inventory_path, 'w') as f: f.write('[{}]\n'.format(hosts)) h1 = '{0} ansible_connection=ssh ansible_ssh_user={1} ansible_ssh_pass={2} ' \ + 'ansible_ssh_private_key_file=~/.ssh/id_juju_sshproxy ' \ 'ansible_python_interpreter=/usr/bin/python3\n'.format(cfg['ssh-hostname'], cfg['ssh-username'], cfg['ssh-password']) f.write(h1) @@ -60,6 +61,12 @@ def create_ansible_cfg(): with open(ansible_config_path, 'w') as f: f.write('[defaults]\n') f.write('host_key_checking = False\n') + # logs playbook execution attempts to the specified path + f.write('log_path = /var/log/ansible.log\n') + + f.write('[ssh_connection]\n') + f.write('control_path=%(directory)s/%%h-%%r\n') + f.write('control_path_dir=~/.ansible/cp\n') # Function to find the playbook path @@ -72,7 +79,7 @@ def find(pattern, path): return result -def execute_playbook(playbook_file, vars=None): +def execute_playbook(playbook_file, vars_dict=None): playbook_path = find(playbook_file, '/var/lib/juju/agents/') cfg = config() @@ -87,7 +94,19 @@ def execute_playbook(playbook_file, vars=None): create_ansible_cfg() create_hosts(cfg, hosts) - call = ['ansible-playbook', playbook_path] - result = subprocess.check_output(call) + call = 'ansible-playbook %s ' % playbook_path + + if vars_dict and isinstance(vars_dict, dict) and len(vars_dict) > 0: + call += '--extra-vars ' + + string_var = '' + for v in vars_dict.items(): + string_var += '%s=%s ' % v + + string_var = string_var.strip() + call += '"%s"' % string_var + + call = call.strip() + result = subprocess.check_output(call, shell=True) return result