-|ansible
|-inventory
|- hosts
|-playbook.yml
sh
[do_server]
localhost ansible_connection=local
---
- name: creating dropltes in DO
hosts: do_server
vars:
ansible_python_interpreter: /usr/bin/python
do_token: "<api token>"
tasks:
- name: Create droplet
digital_ocean_droplet:
state: present
name: "<name>"
region: "<region>"
size: "<size>"
image: "<image>"
unique_name: yes
oauth_token: "{{ do_token }}"
Example
---
- name: creating dropltes in DO
hosts: do_server
vars:
ansible_python_interpreter: /usr/bin/python
do_token: "xxx"
tasks:
- name: Create droplet
digital_ocean_droplet:
state: present
name: "test-create-droplet"
region: "sgp1"
size: "1gb"
image: "ubuntu-20-04-x64"
unique_name: yes
oauth_token: "{{ do_token }}"
จากนั้น สั่งทำงาน playbook
$ ansible-playbook -i inventory playbook.yml
...
PLAY [creating dropltes in DO] ********************************************************************************
TASK [Gathering Facts] *************************************************************************************************
ok: [localhost]
TASK [Create droplet] **************************************************************************************************
changed: [localhost]
PLAY RECAP *************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0