Notes I took while working with Ansible for the first time.

  • terms (source):
    • orchestration tools: designed to provision the servers themselves, e.g. CloudFormation, Terraform
    • configuration management tools: designed to install and manage software on existing servers, e.g. Chef, Puppet, Ansible, and SaltStack
  • Ansible is a procedural configuration management tool
  • list hosts that will be targeted by the given playbook

      $ ansible-playbook pb.yml -i ../environments/dev --list-hosts
    
  • verbose mode up to 3 levels

      $ ansible-playbook pb.yml -i ../environments -vvv
    
  • role_path is relative the location of the ansible.cfg ansible config file
  • dry run

      $ ansible-playbook pb.yml --check
    
  • multistage environments

      ├── environments
      │   ├── cross_env_vars
      │   ├── dev
      │   │   ├── ec2.ini -> ../ec2.ini
      │   │   ├── ec2.py -> ../ec2.py
      │   │   └── group_vars
      │   │       ├── all
      │   │       │   └── cross_env_vars -> ../../../cross_env_vars
      │   │       └── tag_role_api
      │   │           └── vars
      │   │           └── vault
      │   ├── prod
      │   │   ├── ec2.ini -> ../ec2.ini
      │   │   ├── ec2.py -> ../ec2.py
      │   │   └── group_vars
      │   │       ├── all
      │   │       │   └── cross_env_vars -> ../../../cross_env_vars
      │   │       └── tag_role_api
      │   │           └── vars
      │   │           └── vault
      │   ├── ec2.ini
      │   └── ec2.py
    
  • with_items using dicts
  • template accepts vars (this is not documented clearly)

      - template: src=test.j2 dest=/tmp/File1
        vars:
          myTemplateVariable: myDirName
    
      - template: src=test.j2 dest=/tmp/File2
        vars:
          myTemplateVariable: myOtherDir