Skip to content
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

Add example of ansible provisioning with playbook #2676

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

afbjorklund
Copy link
Member

@afbjorklund afbjorklund commented Oct 2, 2024

Example for:

This has the same problem with relative paths, as was fixed for the scripts:

INFO[0022] Waiting for ansible playbook "./ansible/playbook.yaml" 
ERROR! the playbook: ./ansible/playbook.yaml could not be found

commit 3b33549

Currently it uses the working directory, so it only works from the git repo top.

$ limactl start ./templates/ansible.yaml

With the awesome Unicode Unicow:

INFO[0067] Waiting for ansible playbook "./templates/ansible/playbook.yaml" 
╭──────────────────────╮
⟨ PLAY [My first play] ⟩
╰──────────────────────╯
        ╲   ^__^
         ╲  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

╭────────────────────────╮
⟨ TASK [Gathering Facts] ⟩
╰────────────────────────╯
        ╲   ^__^
         ╲  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

ok: [ansible]
╭───────────────────────────────────────────────╮
⟨ TASK [hostname : write hostname using jinja2] ⟩
╰───────────────────────────────────────────────╯
        ╲   ^__^
         ╲  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

ok: [ansible]
╭──────────────────────╮
⟨ TASK [Ping my hosts] ⟩
╰──────────────────────╯
        ╲   ^__^
         ╲  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

ok: [ansible]
╭──────────────────────╮
⟨ TASK [Print message] ⟩
╰──────────────────────╯
        ╲   ^__^
         ╲  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

ok: [ansible] => {
    "msg": "Hello world"
}
╭────────────╮
⟨ PLAY RECAP ⟩
╰────────────╯
        ╲   ^__^
         ╲  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

ansible                    : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

@jandubois
Copy link
Member

Is there a way to reference environment variables from inside the playbook?

I realized that tests in #2570 don't verify that the $PARAM_FOO variables are visible to ansible provisioning (and probably they aren't). So it would be good if we could incorporate a test for that in the example?

@afbjorklund
Copy link
Member Author

afbjorklund commented Oct 2, 2024

Is there a way to reference environment variables from inside the playbook?

I think you can do something like {{ lookup('env','ENV_VAR') }}

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/env_lookup.html

Then there is the ansible_env, but that it set rather than get

@afbjorklund
Copy link
Member Author

afbjorklund commented Oct 2, 2024

I will add a separate test for params, they should be propagated but they fail to validate:

field param key "ANSIBLE" is not used in any provision, probe, copyToHost, or portForward

We will just add them to the environment of the ansible-playbook (local) execution.

Currently the playbook is relative to the current workdir,
it should probably be relative to the lima.yaml instead.

The YAML syntax and the directory layout has been modified
slightly from the original, to work with Lima's setup.

Signed-off-by: Anders F Björklund <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants