cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor_Chandler
Mission Specialist
Mission Specialist
  • 4,184 Views

Ansible playbook

Hello all,

I was reading a resource that was covering some fundamentals on Ansible, and when I got to the short section on modules, the following sentence appeared:  "When used in a task, a module generally ensures that some particular aspect of the machine
is in a particular state."

What's prompting a query from me is the piece that I've highlighted in red. I immediately
asked myself why the need to begin the sentence with "When used in a task".  In a
playbook, is a module used in any place other than a task?  

Thanks all.

 

 

 

Labels (2)
6 Replies
BramMertens
Flight Engineer
Flight Engineer
  • 4,136 Views

Hi,

You can use modules in ad hoc commands as well.

E.g.

ansible atlanta -m ansible.builtin.copy -a "src=/etc/hosts dest=/tmp/hosts"

 But the sentence you posted applies to ad hoc commands as well.

I can't think of any way to use a module where this would not apply.

HTH

RHCE 100-015-239
Trevor_Chandler
Mission Specialist
Mission Specialist
  • 3,848 Views

It helped very much.

Many thanks Bran.

 

0 Kudos
andkra
Flight Engineer Flight Engineer
Flight Engineer
  • 4,046 Views

Hello,

hold in mind ...

One playbook (yml file) consists of one or more plays which run one or more tasks against one or more hosts. 

Playbook (yml file)
|-- Play
|----Tasks
|------ Task with one module (eg. debug, user, copy, ...)
|------ Task with one module (eg. debug, user, copy, ...)
|------ Task with one module (eg. debug, user, copy, ...)
|-- Play
|----Tasks
|------ Task with one module (eg. debug, user, copy, ...)
|------ Task with one module (eg. debug, user, copy, ...)

 

Regards
Andreas

Trevor_Chandler
Mission Specialist
Mission Specialist
  • 3,847 Views

Very big help!!!

Thanks Andkra.

0 Kudos
JG_Kootstra
Flight Engineer Flight Engineer
Flight Engineer
  • 3,863 Views

Hi @Trevor_Chandler ,

As @andkra and @BramMertens mention, we cannot come up with a situation where modules are used outside of a task. It just meant to clarify the usage, it may look like overhead.

ansible adhoc IHMO is just starting a single task outside a playbook.

Regards,

Jan Gerrit

Trevor_Chandler
Mission Specialist
Mission Specialist
  • 3,846 Views

Wonderful explanation JG.
Very big help.

Many thanks!!!!

 

Join the discussion
You must log in to join this conversation.