From d03e39704e8148fa1cf1869c0e5003ecf48c4f57 Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Mon, 15 Jan 2018 09:45:14 +0100 Subject: Fix cloud init runcmd templating Signed-off-by: Bogdan Dobrelya --- playbooks/openstack/advanced-configuration.md | 12 ++++++------ roles/openshift_openstack/templates/user_data.j2 | 13 +++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/playbooks/openstack/advanced-configuration.md b/playbooks/openstack/advanced-configuration.md index 6fbfca3dc..df53f3681 100644 --- a/playbooks/openstack/advanced-configuration.md +++ b/playbooks/openstack/advanced-configuration.md @@ -291,15 +291,15 @@ possible, like this `provision_install_custom.yml` example playbook: The playbook leverages a two existing provider interfaces: `provision.yml` and `install.yml`. For some cases, like SSH keys configuration and coordinated reboots of servers, the cloud-init runcmd directive may be a better choice though. User specified -shell commands for cloud-init need to be lists, for example: +shell commands for cloud-init need to be either strings or lists, for example: ``` - openshift_openstack_cloud_init_runcmd: - - ['echo', 'foo'] - - ['reboot'] + - set -vx + - systemctl stop sshd # fences off ansible playbooks as we want to reboot later + - ['echo', 'foo', '>', '/tmp/foo'] + - [ ls, /tmp/foo, '||', true ] + - reboot # unfences ansible playbooks to continue after reboot ``` -The commands should not use JSON escaped characters: `> < & '`. So the command -`['foo', '>', '"bar"', '<', "'baz'", "&"]` is a bad one, while -`['echo', '"${HOME}"']` is OK. **Note** To protect Nova servers from recreating when the user-data changes via `openshift_openstack_cloud_init_runcmd`, the diff --git a/roles/openshift_openstack/templates/user_data.j2 b/roles/openshift_openstack/templates/user_data.j2 index e130e71c3..352744285 100644 --- a/roles/openshift_openstack/templates/user_data.j2 +++ b/roles/openshift_openstack/templates/user_data.j2 @@ -13,8 +13,17 @@ write_files: Defaults:openshift !requiretty {% if openshift_openstack_cloud_init_runcmd %} -runcmd: + - path: /root/ansible_install.sh + permissions: '0544' + content: | {% for cmd in openshift_openstack_cloud_init_runcmd %} - - {{ cmd|map('string')|list|tojson }} +{% if cmd is string %} + {{ cmd }} +{% elif cmd is iterable %} + {{ cmd|join(' ') }} +{% endif %} {% endfor %} + +runcmd: + - /root/ansible_install.sh {% endif %} -- cgit v1.2.1