Skip to content

Instantly share code, notes, and snippets.

@brycemcd
Last active September 27, 2018 02:43
Show Gist options
  • Save brycemcd/d282bad2ab439cb4d6a2f50c1c8bdc21 to your computer and use it in GitHub Desktop.
Save brycemcd/d282bad2ab439cb4d6a2f50c1c8bdc21 to your computer and use it in GitHub Desktop.
A smattering of frequently used commands I use. This will help prevent excessive load on Google's systems.

Ansible Cheatsheet

A smattering of frequently used commands I use. This will help prevent excessive load on Google's systems.

NOTE: most examples are copied and pasted from the documentation. Attribution belongs to the contributors of the documentation!

Template

http://docs.ansible.com/ansible/latest/template_module.html

- template:
    src: /mytemplates/foo.j2
    dest: /etc/file.conf
    owner: bin
    group: wheel
    mode: 0644

Line in file

http://docs.ansible.com/ansible/latest/lineinfile_module.html

- lineinfile:
    path: /tmp/testfile
    line: '192.168.1.99 foo.lab.net foo'
    insertafter: EOF

File

http://docs.ansible.com/ansible/latest/file_module.html

- file:
    path: /etc/foo.conf
    owner: foo
    group: foo
    mode: 0644
    
# create a directory if it doesn't exist
- file:
    path: /etc/some_directory
    state: directory
    mode: 0755

Users

# Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups
- user:
    name: james
    shell: /bin/bash
    groups: admins,developers
    append: yes

Apt

  - name: install packages
    apt:
        name: "{{item}}"
        state: latest
        update_cache: yes
        install_recommends: yes
    with_items:
        - zsh
        - git
        - vim
        - tmux
        - curl
        - postgresql-client-common
        - openssh-server
        - net-tools

    become: yes
    become_method: sudo

Git

http://docs.ansible.com/ansible/latest/git_module.html

- git:
    repo: 'https://foosball.example.org/path/to/repo.git'
    dest: /srv/checkout
    version: release-0.22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment