-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansible.txt
More file actions
76 lines (74 loc) · 3.92 KB
/
ansible.txt
File metadata and controls
76 lines (74 loc) · 3.92 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
configuration management
chef-Need to install agent on target machines
puppet/ruby - Need to install agent on target machines
ansible/YAML
Agentless
control node- anisble installed on the machine
Manage node - all the machines which are used to install software (ex: windows, linux, debain)
configuration management (installation of software)
provisioning (creation of ec2 instance on aws,gcp,azure)
deployment (because using control node we can deploy anything on manage node)
network automation (automaiton of vlan)
anisble and teeraform both can be used as provisioning, but terraform core skill is used as IAC
control node should be installed on debain,linux or unix operating systems
WSL (windows subsystem for linux distribution on windows system)
username: ubuntu pwd:DevOps321
>explorer.exe . - to access windows current working directory of wsl
>chmod 400 <pem file name>
> ssh-copy-id -f "-o IdentityFile <path of pem file>" ubuntu@host
> ssh "-o IdentityFile <path of pem file>" ubuntu@host>
>eval `ssh-agent -s`(To start agent once again and add passpharse for once for thsat session)
>ssh-add ~/.ssh/id_rsa( for enter passphare for key for password less authentication from wsl to cloud)
password authentication
> sudo vim /etc/ssh/sshd_config.d/60-cloudimg-settings.conf
> sudo vim /etc/ssh/ (if not using ec2 instance navigate to this path and update ssh_config folder)
>\\wsl$ - path of wsl directory
>wsl --install
>wsl --list --online
>wsl --install -d <DistroName>
>wsl --install -d <Distribution Name>
>pip install anisble
>sudo apt install ansible
>ansible --version
two ways of authentication (ssh keys and password)
only first time need to provide password to authenticate from machine a to b or pem file
Inventory file is heart of ansible (inventory.ini)
If inventory file is not provided we can provide details in /etc/ansible/hosts
>ansible -i inventory.ini -m ping all
>ansible -i inventory.ini -m ping ubuntu@host
>ansible -i inventory.ini -m ping <groupname>
upgrading ansible solves ModuleNotFoundError: No module named 'ansible.module_utils.six.moves' with beloe command
python3 -m pip install --upgrade --user ansible
YAML syntax
starts with ---
---
name: sivarao
age: 32
work: yes
ansible playbook
Inside playbook we can write multiple plays
Based on the task number of plays will be decided
> ansible-playbook -i <inventoryfile> <playbook>
check mode used to implement playbook before running in production
> ansible-playbook --check playbook.
to address Readability and modularitiy in ansible concept of roles exists
when complicated ansible playbooks are written roles must be used
> ansible-galaxy role init <role name>
> ansible galaxy is used to share created roles across your organization
> Different folders in ansible roles
> var, tasks, meta, handlers(this are the tasks executed based on other tasks execution), defaults(default values), files and templates (when you want
change the content of file dynamically)
ansible follows jinga2 templating language
>ls -ltr
>anisble-galaxy role -h
#Talking to api of resources using control node and create ec2 instances
>collections - Apart from the built in modules related to ansible
> ansible vault to keep api keys
> boto3 module is used to install on control node to talk to aws
> ansible-galaxy collection install <collection name>
openssl rand -base64 2048 > vault.pass
> ansible-vault create group_vars/all/pass.yml --vault-password-file vault.pass
> ansible-playbook -i inventory.ini ec2_create.yaml --vault-password-file vault.pass
the precidence declaration of variables declare in vars take more priority than in defaults
extra vars has the highest precidence which was created during adhoc
group vars