Skip to content
Snippets Groups Projects
Commit 2bcff0eb authored by ale's avatar ale
Browse files

Allow controlling ansible_become and user-related params

Using a command-line flag.
parent a66d3074
No related branches found
No related tags found
1 merge request!304Fix CI issues with vmine / floatup
...@@ -162,13 +162,7 @@ DEFAULT_VARS = { ...@@ -162,13 +162,7 @@ DEFAULT_VARS = {
# Ansible inventory (hosts are created dynamically). # Ansible inventory (hosts are created dynamically).
'inventory': { 'inventory': {
'hosts': {}, 'hosts': {},
'group_vars': { 'group_vars': {},
'vagrant': {
'ansible_user': 'vagrant',
'ansible_become': True,
'ansible_ssh_private_key_file': '~/.vagrant.d/insecure_private_key',
},
},
}, },
# Ansible configuration. # Ansible configuration.
...@@ -346,7 +340,7 @@ def _render_skel(target_dir, ctx): ...@@ -346,7 +340,7 @@ def _render_skel(target_dir, ctx):
def command_create_env(path, services, passwords, playbooks, def command_create_env(path, services, passwords, playbooks,
roles_path, num_hosts, additional_host_groups, roles_path, num_hosts, additional_host_groups,
additional_configs, ram, domain, infra_domain, additional_configs, ram, domain, infra_domain,
extra_vars): become, extra_vars):
all_vars = DEFAULT_VARS all_vars = DEFAULT_VARS
# Set paths in the internal config. # Set paths in the internal config.
...@@ -355,6 +349,20 @@ def command_create_env(path, services, passwords, playbooks, ...@@ -355,6 +349,20 @@ def command_create_env(path, services, passwords, playbooks,
all_vars['passwords_yml_path'] = passwords all_vars['passwords_yml_path'] = passwords
all_vars['playbooks'] = playbooks all_vars['playbooks'] = playbooks
# Set connection-related user parameters.
if become == 'root':
all_vars['inventory']['group_vars']['vagrant'] = {
'ansible_user': 'root',
'ansible_become': False,
}
else:
all_vars['inventory']['group_vars']['vagrant'] = {
'ansible_user': become,
'ansible_become': True,
# For legacy compatibility reasons.
'ansible_ssh_private_key_file': '~/.vagrant.d/insecure_private_key',
}
# Extend the Ansible roles_path. # Extend the Ansible roles_path.
if roles_path: if roles_path:
for rpath in roles_path.split(':'): for rpath in roles_path.split(':'):
...@@ -548,6 +556,9 @@ memberships, using the --additional-host-group command-line option. ...@@ -548,6 +556,9 @@ memberships, using the --additional-host-group command-line option.
create_env_parser.add_argument( create_env_parser.add_argument(
'--ram', metavar='MB', type=int, default=3072, '--ram', metavar='MB', type=int, default=3072,
help='RAM for each VM when using --vagrant (default: 3072)') help='RAM for each VM when using --vagrant (default: 3072)')
create_env_parser.add_argument(
'--become', metavar='USER', default='vagrant',
help='ansible_user, disable ansible_become if "root"')
create_env_parser.add_argument( create_env_parser.add_argument(
'--additional-host-group', metavar='GROUP=HOST1[,HOST2...]', '--additional-host-group', metavar='GROUP=HOST1[,HOST2...]',
dest='additional_host_groups', dest='additional_host_groups',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment