Execute (shell) commands
(ctx, config)
| 1568 | |
| 1569 | |
| 1570 | def shell(ctx, config): |
| 1571 | """ |
| 1572 | Execute (shell) commands |
| 1573 | """ |
| 1574 | cluster_name = config.get('cluster', 'ceph') |
| 1575 | |
| 1576 | args = [] |
| 1577 | for k in config.pop('env', []): |
| 1578 | args.extend(['-e', k + '=' + ctx.config.get(k, '')]) |
| 1579 | for k in config.pop('volumes', []): |
| 1580 | args.extend(['-v', k]) |
| 1581 | |
| 1582 | config = template.expand_roles(ctx, config) |
| 1583 | config = template.transform(ctx, config, config) |
| 1584 | for role, cmd in config.items(): |
| 1585 | (remote,) = ctx.cluster.only(role).remotes.keys() |
| 1586 | log.info('Running commands on role %s host %s', role, remote.name) |
| 1587 | if isinstance(cmd, list): |
| 1588 | for cobj in cmd: |
| 1589 | sh_cmd, stdin = _shell_command(cobj) |
| 1590 | _shell( |
| 1591 | ctx, |
| 1592 | cluster_name, |
| 1593 | remote, |
| 1594 | ['bash', '-c', sh_cmd], |
| 1595 | extra_cephadm_args=args, |
| 1596 | stdin=stdin, |
| 1597 | ) |
| 1598 | |
| 1599 | else: |
| 1600 | assert isinstance(cmd, str) |
| 1601 | _shell(ctx, cluster_name, remote, |
| 1602 | ['bash', '-ex', '-c', cmd], |
| 1603 | extra_cephadm_args=args) |
| 1604 | |
| 1605 | |
| 1606 | def _shell_command(obj): |