Skip to content

Ansible Playbooks

Created: 2016-02-22 16:56:38 -0800 Modified: 2016-02-23 12:08:06 -0800

Incredibly basic playbook to touch a file

Section titled Incredibly basic playbook to touch a file

  • hosts: botland

remote_user: adam

tasks:

  • name: Test task

command: touch ~/test.txt

To get started with this, you can create a hosts file that has a “[botland]” group with a valid server IP in it. Then, you can run ansible-playbook foo.yml -i hosts

Create folders, copy files, install with NPM

Section titled Create folders, copy files, install with NPM

  • hosts: botland

vars:

homeDir: /home/adam

remote_user: adam

tasks:

  • name: Create folder

file: path=~/this/is/a/test state=directory

  • name: Upload payload

copy: src=/Ansible/payload.txt dest=/this/is/a/test

  • name: Install package.json

npm: path={{ homeDir }}/code/test

Upload SSH key (with correct mode) and git pull

Section titled Upload SSH key (with correct mode) and git pull

Note: the mode needs to be “600” so that only the owner has permissions to read/write. The leading 0 is to signify that it’s an octal number.


  • hosts: botland

vars:

homeDir: /home/adam

remote_user: adam

tasks:

  • name: Upload Bot Land Deploy Key

copy: src=/.ssh/bitbucket_botland_deploy_key dest=/.ssh/ mode=0600

  • name: Git test

git: repo=git@bitbucket.org:onaimada/botlandinfra.git key_file={{ homeDir }}/.ssh/bitbucket_botland_deploy_key dest={{ homeDir }}/code/infra accept_hostkey=yes