-
Notifications
You must be signed in to change notification settings - Fork 652
Embed ansible playbooks in instance templates #3442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Currently it works, because the playbook is just a local path passed to provision:
- mode: ansible
playbook: ./templates/ansible/playbook.yaml So any files that are next to that playbook (like roles), are available to the playbook by default. - name: My first play
hosts: all
tasks:
- name: Ping my hosts
ansible.builtin.ping:
- name: Print message
ansible.builtin.debug:
msg: Hello world
roles:
- hostname https://docs.ansible.com/ansible/latest/tips_tricks/sample_setup.html The recommendation from upstream is to use a git repository ( But then we need to add git (and tar, for directories?) support to Or do some kind of recursive adding of files as yaml binary objects in a yaml map... roles:
hostname:
tasks:
main.yaml:
---
- name: write hostname using jinja2
ansible.builtin.template:
src: templates/test.j2
dest: /tmp/hostname
templates:
test.j2:
My name is {{ ansible_facts['hostname'] }} |
Related to:
But for playbook, rather than script. An alternative would be to skip the Ansible playbook provisioning, and use the ssh.config files for the Ansible inventory? Then it should be not so much work to run inventory.yaml lima:
hosts:
ansible:
ansible_connection: ssh
ansible_host: lima-ansible
ansible_ssh_common_args: -F /home/anders/.lima/ansible/ssh.config If we "assume" the ssh.config is included, then we can just use "lima-ansible" host (since ssh is the default connection). Simple enough to be generate on the fly, in the INI format: https://docs.ansible.com/ansible/latest/inventory_guide/ hosts (inventory) [lima]
ansible ansible_host=lima-ansible Also works better for multiple instances, since otherwise you have to "merge" the
|
i.e.
provision.playbook
should be converted to use locator as wellCurrently it is being read into script, but should also be for playbook.
NOTE: The playbook is recursive, so needs to be parsed to be embedded...
Unfortunately Ansible does not provide a good way to use a single yaml file.
I have no idea if embedding works for scripts that include functions from files...
Originally posted by @afbjorklund in #2676 (comment)
The text was updated successfully, but these errors were encountered: