Skip to content

Instantly share code, notes, and snippets.

@asalhani
Last active December 15, 2019 15:03
Show Gist options
  • Save asalhani/9f5e68b50216b5db5f723c42c43b28fa to your computer and use it in GitHub Desktop.
Save asalhani/9f5e68b50216b5db5f723c42c43b28fa to your computer and use it in GitHub Desktop.
Ansiable Notes

Inventory sample:

# Sample Inventory File

# Web Servers
web_node1 ansible_host=web01.xyz.com ansible_connection=winrm ansible_user=administrator ansible_password=Win$Pass
web_node2 ansible_host=web02.xyz.com ansible_connection=winrm ansible_user=administrator ansible_password=Win$Pass
web_node3 ansible_host=web03.xyz.com ansible_connection=winrm ansible_user=administrator ansible_password=Win$Pass

# Database Servers
sql_db1 ansible_host=sql01.xyz.com ansible_connection=ssh ansible_user=root ansible_ssh_pass=Lin$Pass
sql_db2 ansible_host=sql02.xyz.com ansible_connection=ssh ansible_user=root ansible_ssh_pass=Lin$Pass

# group of nodes
[db_nodes]
sql_db1
sql_db2

[web_nodes]
web_node1
web_node2
web_node3

# group of groups
[us_nodes:children]
boston_nodes
dallas_nodes

Ad-hoc command stracture:

  ansible <hosts> -a <command>
  ansible <hosts> -m <module> -i <invetroy-file>
  ansible all -m ping -i inventory.txt

Playbook file sample:

-
  name: Test connectity to target servers
  hosts: all
  tasks:
    - name: Ping test
      ping:

Excute playbook command:

  ansible-playbook playbook-file.yaml -i invintory-file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment