-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansibleNotes
More file actions
78 lines (78 loc) · 3.29 KB
/
ansibleNotes
File metadata and controls
78 lines (78 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash NOT A REAL SHELL SCRIPT!
# This is a cut'n'paste scriptlet
# be sure to read & understand what you're cutting & pasting!
#
# ISO date stamp
`date +%Y%m%d-%H%M`
###############################################################################
#Configuration Locations - first found ########################################
# Contents of ${ANSIBLE_CONFIG}
# ./ansible.cfg
# ~/.ansible.cfg
# /etc/ansible/ansible.cfg
###############################################################################
#Add-hoc commands
# test connection
ansible all -m ping
# Common flags:
# -o print each result on one line
# -k ask for password (i.e., don't use key-based)
# -b, --become run operation using sudo (default, see become-method) (also -s, --sudo [deprecated])
# -C, --check don't make changes, test what would be changed
# -f <num> run <num> parallel processes (default 5)
# -u <user> log into servers as <user>
# -B <num> run in background, kill task after <num> seconds
# -t <dir> save contents in this output <dir>, results in file named for each host
# --become-method=BECOME_METHOD
# Privilege escalation method to use (default=sudo), valid choices: [ sudo | su |
# pbrun | pfexec | runas | doas | dzdo ]
#
# Execute arbitrary commands, no -m will imply -m command
ansible <hostpattern> -a "<command>"
ansible <hostpattern> -m command -a "<command>"
# Execute arbitrary commands in a shell environment
ansible <hostpattern> -m shell -a "<command>"
# install/remove a package via yum
ansible <hostpattern> -m yum -a "name=<package> state=[present|absent]" --sudo
#
###############################################################################
#Copy file to hosts
ansible <hostpattern> -m copy -a "src=</path/to/src/file> dest=</path/to/dest/file> mode=755"
#Copy file from hosts
ansible <hostpattern> -m fetch -a "src=</path/to/src/file> dest=</path/to/dest/directory>"
#
###############################################################################
#Get info on a host
ansible <host> -m setup
# filter keys
ansible <host> -m setup -a 'filter=<keypattern>'
###############################################################################
#Vault commands [manage encrypted ansible vars files (YAML)]
ansible-vault encrypt <file>
# when running a command w/encrypted file, add flag --ask-vault-pass
#
###############################################################################
#Doc commands [show documentation on Ansible modules]
ansible-doc [-M <modulepath>] <modulename>
#
###############################################################################
#Pull commands [pull playbooks from VCS server and run them using this machine as the target.]
ansible-pull
#
###############################################################################
#Galaxy commands [manage roles using galaxy.ansible.com (or file)]
ansible-galaxy
#
###############################################################################
#Playbook Commands
# Syntax check
ansible-playbook --syntax-check <pbfile>
# List hosts or tasks
ansible-playbook <pbfile> --list-[hosts|tasks]
# Run on all hosts defined
# test run add -C
# dry run add -C -D
# single host add -l <hostname>
ansible-playbook <pbfile>
#
###############################################################################