Skip to content

Instantly share code, notes, and snippets.

@keyboardscience
Created July 22, 2016 20:01
Show Gist options
  • Select an option

  • Save keyboardscience/4324c6116cd27e8660b5842694a1afc7 to your computer and use it in GitHub Desktop.

Select an option

Save keyboardscience/4324c6116cd27e8660b5842694a1afc7 to your computer and use it in GitHub Desktop.
---
- name: Working with constrained remote host
hosts: remotes_without_python27
gather_facts: yes # this may fail
tasks:
- name: Render template locally
delegate_to: localhost
template:
src: templates/file_template.j2
dest: rendered_templates/file.extension
# Ensure there are not issues with variable context
- name: Save rendered template to fact
set_fact:
file_content: "{{ lookup('file', 'rendered_templates/file.extension') }}"
- name: Write the content into a file on remote
raw: "echo -e '{{ file_content }}' | sudo tee /path/to/destination.extension"
- name: Fix permissions on file
raw: "chmod {{ octal_permissions | default('700') }} /path/to/destination.extension && chown {{ owner | default('root') }}:{{ group | default('root') }} /path/to/destination.extension"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment