0
votes

I need to use a provisioning tool called vcommander looks like this tool supports running ansible locally on the provisioned host only, and you need to provide him only the playbook to run.

I already have working ansible roles which includes tasks and templates for examples the ntp role looks toughtly like below:

ls -1 roles/ntp/

defaults
LICENSE
meta
README.md
tasks
templates

the main task looks something like this:

cat roles/ntp/tasks/main.yml

---

- name: "Configure ntp.conf"
  template:
    src: "ntp.conf.j2"
    dest: "/etc/ntp.conf"
    mode: "0644"
    become: True

- name: Updating time zone
  shell: tzdata-update

- name: Ensure NTP-related packages are installed.
  package:
  name: ntp
 state: present

- name: Ensure NTP is running and enabled as configured.
  service:
  name:  ntpd
 state: started
enabled: yes

and the template looks like this:

cat roles/ntp/templates/ntp.conf.j2

{{ ansible_managed }}

restrict 127.0.0.1
restrict -6 ::1

server 127.127.1.0
fudge   127.127.1.0 stratum 10

driftfile /var/lib/ntp/drift
keys /etc/ntp/keys

Is there a way to include the main.yml and the ntp.conf.j2 (template) and other files included in the roles into one yml file? Please provide an example.

1

1 Answers

0
votes

Are you asking for a playbook that applies your ntp role to localhost?

It would look like this:

cat playbook.yml

- hosts: localhost
  roles:
    - ntp

See docs: https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html#using-roles