Skip to content

Latest commit

 

History

History
64 lines (54 loc) · 1.25 KB

LAB3.md

File metadata and controls

64 lines (54 loc) · 1.25 KB

Lab 3 - Using collections

  1. Using collections in playbook.
  • Reference a collection content by its fully qualified collection name (FQCN).
  • Using FQCN is recommended option.
- hosts: all
  tasks:
   - name: Execute module from collection
     my_namespace.my_collection.module:
      option1: value
      option2: value
       ...
  1. Importing role from collection.
  • Import role in playbook.
- hosts: all
  tasks:
   - name: Import role from collection
     import_role:
      name: my_namespace.my_collection.role_name

or simply

- hosts: all
  collections:
    - my_namespace.my_collection

  tasks:
    - name: Import role from collection
      import_role:
       name: role_name
  1. First play example.
# Inventory file:
[lab]
managed_server  ansible_connection=local

# first_play.yml
- hosts: all
  gather_facts: no

  tasks:
   - name: Simple ping
     ansible.builtin.ping:

   - name: Check ssh service
     ansible.builtin.service:
      name: ssh
      state: started

# run
ansible-playbook -i inventory first_play.yml
  1. More examples in Lab 4.