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

no example of import_tasks or strategy #316

Open
unusualevent opened this issue Jan 20, 2023 · 1 comment
Open

no example of import_tasks or strategy #316

unusualevent opened this issue Jan 20, 2023 · 1 comment

Comments

@unusualevent
Copy link

is it possible to make an example of import_tasks, and an example of strategy, and an example of them together?

I had an original problem with the code, but the docs and debugging tools and examples were unhelpful.

what I was trying to solve

wanted to set a strategy for tasks to free (like usual) but import a bunch of tasks into a main task in a role. maybe this is a bad pattern or that's supposed to be set inside the playbook itself (along with which tasks of a role to run... but then... why do roles have a main.yml??

the errors I had

ansible shows a conflicting action statement during a run of a playbook:

ERROR! conflicting action statements: strategy, import_tasks

the example in the docs for import_tasks doesn't tell you what yaml file the code is (a common problem throughout the docs) - I'm not sure if this is a playbook, a task, what have you: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_tasks_module.html

yaml-schema shows "matches a schema that is not allowed", but doesn't give the error

an example file

filename: roles/something/tasks/main.yml

- name: example
  strategy: free
  tasks:
     - import_tasks: subtask.yml # done because I couldn't set strategy in the other task. should I be setting this in the playbook?
# alternatively:
- name: example
  strategy: free
  import_tasks: subtask.yml # done because I couldn't set strategy in the other task. should I be setting this in the playbook?

the debug process

  1. tried re-reading docs (it's been a while since I messed with playbooks and didn't have any old code) - this stuff is at least trying to have examples which is better than auto-generated docs for rust/golang/openapi3...
  2. yaml schema barfed undescriptively
  3. ansible-lint crashed (which, maybe it's useful?)
  4. googling ansible schema pulls up https://github.com/ansible/schemas
  5. ansible-schemas repo says ansible-lint maintains it
  6. however ansible-lints docs (https://ansible-lint.readthedocs.io/rules/schema/) say the schema rules are maintained in ansible-navigator (https://github.com/ansible/ansible-navigator), all of which aren't solid examples...
  7. which lead me to google and find this examples repo...
  8. which doesn't cover either import_tasks or strategy
  9. made ticket in ansible examples
  10. re-read docs really hard. it's subtle but I thiiiink the ansible maintainers are trying to say "this file is a playbook".

conclusion

...maybe a longterm fix is to have the ansible docs website show what each code snippet is (playbook, task, etc)...

is it possible to make a correct example using both??

@RayJin2000
Copy link

I think your playbook is missing hosts:

have you tried:

- name: example
  strategy: free
  hosts: localhost
  tasks:
     - import_tasks: subtask.yml 

may have a look here import_tasks_module

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

No branches or pull requests

2 participants