Ansible module notes

From wikinotes

Ansible uses modules as you primary means for interacting with a given system. Below I have listed some of the more commonly used ansible modules. A full list is available here: http://docs.ansible.com/ansible/list_of_all_modules.html


copy/sync

ansible all  -m copy -a "src=/src/file dest=/dest/file"        ## scp files
ansible all  -m synchronize ... (lookup) ## rsync files

file

create/delete files/dirs, in addition to modifying permissions.

ansible all -m file -a "dest=/path/to/file  mode=600 owner=will group=will"                                ## change permissions
ansible all -m file -a "dest=/path/to/file  mode=755 owner=will group=will   state=directory"        ## mkdir -p
ansible all -m file -a "dest=/path/to/file                                   state=absent"            ## delete

package-managers

## 'package' abstsracts across all known package manages.
## whether pacman, pkgng, apt-get, yum, it installs in all situations.
- name:    Install zsh
  package: name=zsh state=latest

users/groups

ansible all -m user -a "name=will password=<encrypted password here>"  # add/modify user
ansible all -m user -a "name=will state=absent"                        # delete user

git

If you're looking for a way to automatically deploy software as the repo receives new commits, take a look at jenkins.

# apparently can push updates as git repo is updated?
ansible webservers -m \
    git -a "repo=git://foo.example.org/repo.git dest=/srv/myapp version=HEAD"

services

ansible webservers -m service -a "name=sshd    state=started"   # start   service
ansible webservers -m service -a "name=sshd    state=restarted" # restart service
ansible webservers -m service -a "name=sshd    state=stopped"   # stop    service