I was hoping, maybe I could pass the missing items in ansible-playbook arguments. The problem is the hosts item : in the playbook used to launch a task file, you tend to give a large scope to it, and I find it dangerous, if one forget the -l parameter in the adhoc command. I was searching a way to avoid specify hosts in the playbook, what would oblige to pass it in arguments.
Thanks for your answer E.T. Le vendredi 9 octobre 2020 à 11:59:22 UTC+2, [email protected] a écrit : > ansible-playbook is meant to run..... ansible playbooks :) > > What you have is a task file. > Playbooks contain tasks. Playbook can import/include tasks files. > To run a playbook you do need the playbook items such as hosts, tasks, etc. > > > On Fri, 9 Oct 2020 at 11:21, Mouton Noir <[email protected]> wrote: > > > > Hi, > > > > Newbie to Ansible, but I already made a lot of things with it. > > One thing, though, I can't do is re-use a task file for adhoc commands > or re-use a playbook in another playbook : > > > > For example, I use a task file (R_packages.yml) in a role, that starts > like this : > > > > - name: Recuperation de la version de R installee > > win_shell: (Get-ItemProperty > HKLM:Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object > DisplayName -like "R for Win*").DisplayVersion > > register: Rversion > > > > I'd like to be able to launch it with an ad hoc command like : > > ansible-playbook R_packages.yml ..... > > But it doesn't work : > > ERROR! 'register' is not a valid attribute for a Play > > > > I had to create a playbook to launch it : > > - hosts: fst-win-tp-bio > > gather_facts: "false" > > tasks: > > - name: Install packages R > > import_tasks: /etc/ansible/roles/fst-win-tp-bio/tasks/R_packages.yml > > > > I didn't fond anything in the doc that makes me understand how I could > make an "hybrid" task/playbook file I could launch both ways > > > > To be clear : This task file is part of a role, and I like to be able to > use it from times to times on adhoc command. > > > > Thanks for your help > > E.T. > > > > -- > > You received this message because you are subscribed to the Google > Groups "Ansible Project" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/e3b038d6-a99d-4b52-b02c-bdc8c9578c84n%40googlegroups.com > . > > > > -- > Dick Visser > Trust & Identity Service Operations Manager > GÉANT > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9e022536-51ad-413e-b080-00af47dbe900n%40googlegroups.com.
