Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cf_remote/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ def install(
assert (trust_keys is None) or hasattr(trust_keys, "__iter__")
# These assertions are checked/ensured in main.py

if demo and not bootstrap:
log.error(
"Cannot start a demo on a non-bootstrapped host (CFEngine would be installed but not started)."
"Please re-run cf-remote install with --bootstrap <hub_name>."
)
return 1

# If there are URLs in any of the package strings and remote_download is FALSE, download and replace with path:
packages = (package, hub_package, client_package)
if remote_download:
Expand Down
40 changes: 32 additions & 8 deletions cf_remote/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@
from cf_remote.utils import save_file
from cf_remote.ssh import scp, ssh_sudo, ssh_cmd, auto_connect

SET_ADMIN_PASSWORD_QUERY = """UPDATE
\"system\"
SET
\"value\" = 'true'
WHERE
\"key\" = 'is_setup_complete';
INSERT
INTO
\"users\"
(\"username\", \"password\", \"salt\", \"name\", \"email\", \"external\", \"active\", \"roles\", \"changetimestamp\") SELECT
'admin',
'SHA=7f062dc2ef82d2b87f012fc17d70c372aa4e2883d9b6c5c1cc7382a5c868b724',
'eWAbKQmxNP',
'admin',
'[email protected]',
false,
'1',
'{admin,cf_remoteagent}',
now()
ON CONFLICT (username,
external) DO UPDATE

SET
password = 'SHA=7f062dc2ef82d2b87f012fc17d70c372aa4e2883d9b6c5c1cc7382a5c868b724',
salt = 'eWAbKQmxNP';"""


@auto_connect
def agent_run(data, *, connection=None):
Expand All @@ -21,15 +47,13 @@ def agent_run(data, *, connection=None):
log.debug(output)


def disable_password_dialog(host):
@auto_connect
def disable_password_dialog(host, *, connection=None):
print("Disabling password change on hub: '{}'".format(host))
api = "https://{}/api/user/admin".format(host)
d = json.dumps({"password": "password"})
creds = "admin:admin"
header = "Content-Type: application/json"
c = "curl -X POST -k {} -u {} -H '{}' -d '{}'".format(api, creds, header, d)
log.debug(c)
os.system(c)
ssh_sudo(
connection,
'/var/cfengine/bin/psql cfsettings -c "{}"'.format(SET_ADMIN_PASSWORD_QUERY),
)


def def_json(call_collect=False):
Expand Down
8 changes: 4 additions & 4 deletions cf_remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def get_info(host, *, users=None, connection=None):


@auto_connect
def install_package(host, pkg, data, *, connection=None):
def install_package(host, pkg, data, demo, *, connection=None):
print("Installing: '{}' on '{}'".format(pkg, host))
output = None
if ".deb" in pkg:
Expand Down Expand Up @@ -325,7 +325,7 @@ def install_package(host, pkg, data, *, connection=None):

if output is None:
log.error("Installation failed on '{}'".format(host))
else:
elif not demo:
m = re.search(r"\#+[^\#]+\#+", output) # filtrate out junk output
if m:
print("\n{}\n".format(m.group(0)))
Expand Down Expand Up @@ -567,7 +567,7 @@ def install_host(
scp(package, host, connection=connection)
package = basename(package)

success = install_package(host, package, data, connection=connection)
success = install_package(host, package, data, demo, connection=connection)
if not success:
# errors already logged
return 1
Expand Down Expand Up @@ -613,7 +613,7 @@ def install_host(
host, connection=connection, call_collect=call_collect
)
demo_lib.agent_run(data, connection=connection)
demo_lib.disable_password_dialog(host)
demo_lib.disable_password_dialog(host, connection=connection)
demo_lib.agent_run(data, connection=connection)
return 0

Expand Down
3 changes: 1 addition & 2 deletions cf_remote/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ def ssh_sudo(connection, cmd, errors=False, needs_pty=False):
assert connection

if connection.needs_sudo:
escaped = cmd.replace('"', r"\"")
cmd = "sudo %s" % escaped
cmd = "sudo %s" % cmd

if needs_pty:
cmd = 'script -qec "%s" /dev/null' % cmd
Expand Down
Loading