Ansible

Learn how to configure Ansible for use with Filebase.

What is Ansible?

Ansible is an open-source automation tool that automates processes such as application deployment, resource provisioning, software installs, and daily tasks. Ansible is available on UNIX-like systems, such as macOS X and Linux distributions.

Read below to learn how to use Ansible with Filebase.

Prerequisites:

Use the following commands to interact with Filebase using Ansible:

Create a New Bucket

Replace the following values:

  • Bucket: New Filebase bucket name

  • Aws_access_key: Filebase Access Key

  • Aws_secret_key: Filebase Secret Key

ansible -i inv_local localhost -m aws_s3 -a "bucket=filebase-bucket s3_url=https://s3.filebase.com mode=create region=us-east-1 aws_access_key=<Filebase-Access-Key> aws_secret_key=<Filebase-Secret-Key>"

Expected Result:

localhost | CHANGED => {
"changed": true,
"msg": "Bucket created successfully."
}

List All Objects in a Bucket

Replace the following values:

  • Bucket: Filebase bucket name

  • Aws_access_key: Filebase Access Key

  • Aws_secret_key: Filebase Secret Key

ansible -i inv_local localhost -m aws_s3 -a "bucket=filebase-bucket s3_url=https://s3.filebase.com mode=list region=us-east-1 aws_access_key=<Filebase-Access-Key> aws_secret_key=<Filebase-Secret-Key>"

Expected Result:

localhost | SUCCESS => {
"changed": false,
"msg": "LIST operation complete",
"s3_keys": [
"image.png"
]
}

Download Files From a Bucket:

Replace the following values:

  • Bucket: Filebase bucket name

  • Aws_access_key: Filebase Access Key

  • Aws_secret_key: Filebase Secret Key

  • Object: Name of object to download

  • Dest: Local download destination path

ansible -i inv_local localhost -m aws_s3 -a "bucket=filebase-bucket s3_url=https://s3.filebase.com mode=get region=us-east-1 aws_access_key=<Filebase-Access-Key> aws_secret_key=<Filebase-Secret-Key> object=filebase-bucket/image.png dest=/Users/Filebase/image.png"

Expected Result:

localhost | CHANGED => {
"changed": true,
"msg": "GET operation complete"
}

Upload Objects To a Bucket:

Replace the following values:

  • Bucket: Filebase bucket name

  • Aws_access_key: Filebase Access Key

  • Aws_secret_key: Filebase Secret Key

  • Object: Name of object to upload

  • Src: Local path to source object

ansible -i inv_local localhost -m aws_s3 -a "bucket=filebase-bucket s3_url=https://s3.filebase.com mode=put region=us-east-1 aws_access_key=<Filebase-Access-Key> aws_secret_key=<Filebase-Secret-Key> object=image.png src=/Users/Filebase/image.png"

Expected Result:

localhost | CHANGED => {
"changed": true,
"msg": "PUT operation complete",
"url": "<https://s3.filebase.com/filebase-bucket/image.png?AWSAccessKeyId=><Filebase-Access-Key>&Expires=1542120731&Signature=<Signature>"
}

Delete All Files From a Bucket

Replace the following values:

  • Bucket: Filebase bucket name

  • Aws_access_key: Filebase Access Key

  • Aws_secret_key: Filebase Secret Key

ansible -i inv_local localhost -m aws_s3 -a "bucket=filebase-bucket s3_url=https://s3.filebase.com mode=delete region=us-east-1 aws_access_key=<Filebase-Access-Key> aws_secret_key=<Filebase-Secret-Key>"

Expected Result:

localhost | CHANGED => {
"changed": true,
"msg": "Object deleted from bucket filebase-bucket."
}

Delete an Individual Object In a Bucket

Replace the following values:

  • Bucket: Filebase bucket name

  • Aws_access_key: Filebase Access Key

  • Aws_secret_key: Filebase Secret Key

  • Object: Object to delete

ansible -i inv_local localhost -m aws_s3 -a "bucket=filebase-bucket s3_url=https://s3.filebase.com mode=delete region=us-east-1 aws_access_key=<Filebase-Access-Key> aws_secret_key=<Filebase-Secret-Key> object=image.png"

Expected Result:

localhost | CHANGED => {
"changed": true,
"msg": "Object deleted from bucket filebase-bucket."
}

Last updated