Repository navigation
Expand file tree
/
Copy pathansible-setup
More file actions
88 lines (74 loc) · 2.57 KB
/
Copy pathansible-setup
File metadata and controls
88 lines (74 loc) · 2.57 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
79
80
81
82
83
84
85
86
87
88
# Ansible Installation
Ansible is an open-source automation platform. It is very, very simple to set up and yet powerful.
Ansible can help you with configuration management, application deployment, task automation.
### Pre-requisites
1. An AWS EC2 instance (on Control node)
### Installation steps:
#### on Amazon EC2 instance
1. Install python and python-pip
```sh
yum install python
yum install python-pip
```
1. Install ansible using pip check for version
```sh
pip install ansible
ansible --version
```
1. Create a user called ansadmin (on Control node and Managed host)
```sh
useradd ansible
passwd ansible
```
1. Below command grant sudo access to ansadmin user. But we strongly recommended using "visudo" command
if you are aware vi or nano editor. (on Control node and Managed host)
```sh
#echo "ansible ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "ansible ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/ansible
```
1. Log in as a ansadmin user on master and generate ssh key (on Control node)
```sh
sudo su - ansible
ssh-keygen
```
1. Copy keys onto all ansible managed hosts (on Control node)
```sh
ssh-copy-id ansadmin@<target-server>
```
1. Ansible server used to create images and store on docker registry.
Hence install docker, start docker services and add ansadmin to the docker group.
```sh
yum install docker
# start docker services
service docker start
service docker start
# add user to docker group
usermod -aG docker ansible
```
1. Create a directory /etc/ansible and create an inventory file called "hosts" add control node and managed hosts IP addresses to it.
### Validation test
```sh
sudo mkdir /etc/ansible
sudo chown -R ansible:ansible /etc/ansible
vi /etc/ansible/ansible.cfg # default ansible_config file
host_key_checking = False
```
### Create Ansible Hosts file
``` sh
localhost
[ubuntu]
172.31.20.135 ansible_user=ubuntu ansible_ssh_private_key_file=~/docker_key.pem
[dbServers]
#54.166.255.168
54.166.255.168 ansible_user=admin ansible_ssh_private_key_file=~/.ssh/id_rsa
#[webServers]
#172.31.85.223
#172.31.37.112 ansible_user=admin ansible_password=land
# 172.31.85.223 ansible_user=ec2-user ansible_ssh_private_key_file=~/aws.pem
172.31.85.223 ansible_user=admin ansible_ssh_private_key_file=~/key.pem
[appServers]
172.31.22.155 ansible_user=ec2-user ansible_ssh_private_key_file=~/docker_key.pem
1. Run ansible command as ansadmin user it should be successful (Master)
```sh
ansible all -m ping
```