Skip to content

Commit 249cd68

Browse files
committed
puppet notes
1 parent 19f9898 commit 249cd68

5 files changed

Lines changed: 1162 additions & 0 deletions

File tree

AddressbookPlaybook.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
---
3+
- hosts: webservers
4+
become: true
5+
become_user: root
6+
tasks:
7+
- name: install tomcat
8+
yum: name=tomcat state=present
9+
- name: start tomcat
10+
service: name=tomcat state=started
11+
- name: install docker
12+
yum: name=docker state=present
13+
- name: start docker
14+
service: name=docker state=started
15+
- name: install git
16+
yum: name=git state=present
17+
- name: get repo
18+
git: repo=https://github.com/Sonal0409/dockerdemo.git dest=/tmp/gitrepo
19+
- name: Build Dockerfile
20+
command: chdir=/tmp/gitrepo docker build -t addressbook:ansible .
21+
- name: run Image
22+
command: docker run -itd -P addressbook:ansible

AnsibleNotes_LMS.txt

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
Ansible Notes
2+
3+
Create 2 instances and start them
4+
5+
Set up on ACM:
6+
********************************
7+
8+
Step1:
9+
**************
10+
go to vim /etc/ssh/sshd_config
11+
12+
i
13+
scroll down
14+
remove the # for password Authentication Yes
15+
Add # for password Authentication No
16+
17+
:wq!
18+
19+
Step 2:
20+
**************
21+
Create password for ec2-user
22+
23+
# passwd ec2-user
24+
Newpassword:
25+
ConfirmPassword:
26+
27+
********************
28+
Step 3:
29+
***********
30+
31+
Add ec2-user in sudoers files and give all permission
32+
33+
# vim /etc/sudoers
34+
35+
i
36+
scroll down
37+
38+
under root add like this
39+
40+
ec2-user ALL=NOPASSWD: ALL
41+
42+
**************************
43+
Step 4:
44+
45+
Restart your sshd connection
46+
47+
# systemctl restart sshd
48+
49+
*******************
50+
51+
Repeat all the 4 steps on Host machine also and restart the sshd connection on host machine.
52+
53+
************************
54+
55+
Install Ansible :
56+
57+
Step 1:
58+
*************
59+
60+
# yum list | grep ansible // you will not find ansible package as default in yum
61+
62+
So install epel replositories and it will ass ansible to yum repository
63+
64+
65+
# yum install epel-release
66+
67+
// copy the command sudo amazon-linux-extras install epel and execute it
68+
69+
# sudo amazon-linux-extras install epel
70+
71+
give y
72+
73+
Complete!
74+
75+
You will ansible package is now available with yum
76+
77+
# yum list | grep ansible
78+
79+
//ansible will be available (wait for few seconds)
80+
81+
82+
# yum install ansible
83+
84+
press y
85+
again press y
86+
Complete!
87+
88+
# ansible --version
89+
90+
version of ansible isntalled will be displayed.
91+
92+
*****************************************
93+
CREATE INVENTORY ON ACM and ADD Host details
94+
*****************************************
95+
96+
# vim /etc/ansible/hosts
97+
98+
Scroll down to end and add
99+
100+
[webservers]
101+
paste private ip of host ==> 172.31.39.169
102+
103+
:wq!
104+
105+
***********************************************
106+
107+
OPEN SECURE SHELL CONNECTION
108+
109+
***********************************************
110+
111+
Step 1: change to ec2-user
112+
113+
# su - ec2-user
114+
115+
# ssh-keygen
116+
117+
press enter
118+
press enter
119+
press enter
120+
121+
ssh key will be generated
122+
123+
Step 2: copy key on to the host
124+
125+
# ssh-copy-id -i ec2-user@private ip of host
126+
127+
press yes
128+
enter passowrd ==>
129+
130+
ssh connection will be done
131+
In the message we will have a command to loginto the host from ACM, execute it
132+
133+
# ssh 'ec2-user@172.31.35.169'
134+
135+
we will be connected to the host
136+
137+
exit
138+
back to ACM
139+
140+
*****************************************
141+
Modules in ANSIBLE
142+
143+
1. adhoc ping command
144+
145+
# ansible -m ping webservers
146+
147+
response will be a pong from all hosts under webservers
148+
149+
150+
Module2 : command
151+
152+
# ansible -m command -a "uptime" webservers
153+
154+
will give the uptime of hosts in webservers
155+
156+
157+
To chekc all modules in ansible
158+
159+
# ansible-doc -l
160+
161+
use up arrow key and down arrow key to scroll up and down.
162+
press q to exit
163+
********************************
164+
165+
Playbook2 -- For TomCat
166+
167+
# sudo vim playbook2.yml
168+
169+
i
170+
171+
---
172+
- hosts: webservers
173+
become: true
174+
become_user: root
175+
tasks:
176+
- name: install tomcat
177+
yum: name=tomcat state=present
178+
- name: start tomcat
179+
service: name=tomcat state=started
180+
- name: deploy war file
181+
get_url:
182+
url=https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war
183+
dest=/usr/share/tomcat/webapps
184+
notify: restart tomcat
185+
handlers:
186+
- name: restart tomcat
187+
service: name=tomcat state=restarted
188+
189+
Syntax check:
190+
191+
# ansible-playbook playbook1.yml --syntax-check
192+
193+
# ansible-playbook playbook1.yml
194+
195+
********************************************
196+
197+
playbook.yml (httpd) and deploy a html page
198+
199+
# sudo vim playbook.yml
200+
201+
i
202+
203+
---
204+
- hosts: webservers
205+
become: true
206+
become_user: root
207+
tasks:
208+
- name: install httpd
209+
yum: name=httpd state=present
210+
- name: start httpd
211+
service: name=httpd state=started
212+
- name: deploy html file
213+
copy: src=/etc/ansible/index.html dest=/var/www/html
214+
notify: restart httpd
215+
handlers:
216+
- name: restart httpd
217+
service: name=httpd state=restarted
218+
219+
:wq!
220+
221+
Check syntax
222+
223+
# ansible-playbook playbook.yml --syntax-check
224+
Now run the playbook
225+
226+
# ansible-playbook playbook.yml
227+
228+
229+
*************************************
230+
231+
docker deplyment
232+
233+
---
234+
- hosts: webservers
235+
become: true
236+
become_user: root
237+
tasks:
238+
- name: install docker
239+
yum: name=docker state=present
240+
- name: start docker
241+
service: name=docker state=started
242+
- name: install git
243+
yum: name=git state=present
244+
- name: get the dockerfile from githib
245+
git: repo=https://github.com/Sonal0409/dockerdemo.git dest=/tmp/gitrepo
246+
- name: build dockerfile
247+
command: chdir=/tmp/gitrepo docker build -t deployimage:ansible .
248+
- name: run the dockerfile
249+
command: docker run -itd -P deployimage:ansible
250+
251+
*****************************************

AnsibleTower Steps.txt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Ansible Tower is supported by the following operating systems:
2+
3+
Red Hat Enterprise Linux 6 64-bit
4+
Red Hat Enterprise Linux 7 64-bit
5+
CentOS 6 64-bit
6+
CentOS 7 64-bit
7+
Ubuntu 12.04 LTS 64-bit
8+
Ubuntu 14.04 LTS 64-bit
9+
Ubuntu 16.04 LTS 64 bit
10+
You should have the latest stable release of Ansible.
11+
12+
64-bit support required (kernel and runtime) and 20 GB hard disk.
13+
14+
Minimum 2 GB RAM (4+ GB RAM recommended) is required.
15+
16+
2 GB RAM (minimum and recommended for Vagrant trial installations
17+
4 GB RAM is recommended /100 forks
18+
For Amazon EC2: Instance size of m3.medium or larger is required for less than 100 hosts and if you have more than 100 hosts, then you require an instance size of m3.xlarge or larger.
19+
20+
For HA MongoDB setups, you can use the below formula for a rough estimate of the amount of space required.
21+
22+
Installation of Ansible Tower
23+
Before you install Ansible Tower, you have to first install and configure Ansible on your operating system and then also install PostgreSQL.
24+
25+
So, first let’s start by installing and configuring Ansible. I will be using Ubuntu – 16.04 version as my operating system.
26+
27+
Install and Configure Ansible on Ubuntu
28+
Step 1: As a root user, configure the Ansible PPA using the below commands.
29+
30+
apt-get install software-properties-common
31+
apt-add-repository ppa:ansible/ansible
32+
Step 2: After configuring, install Ansible using the below commands.
33+
34+
apt-get update
35+
apt-get install ansible
36+
After you are done installing, install PostgreSQL.
37+
38+
Installing PostgreSQL
39+
Use the below commands, to install PostgreSQL.
40+
41+
apt-get update
42+
sudo apt-get install postgresql postgresql-contrib
43+
Download Ansible Tower
44+
Step 1.1: Once you are done installing Ansible, register to download the Ansible – Tower.
45+
46+
Step 1.2: You will receive an email after you register to download the Ansible Tower. Open your mail and then click on the download button, to download.
47+
48+
Step 1.3: Then extract the Ansible Tower installation tool using the below commands.
49+
50+
tar xvzf ansible-tower-setup-latest.tar.gz
51+
ansible-tower-setup-<tower_version>
52+
where tower-version, is the version of the tower you have downloaded.
53+
54+
Step 2: After that set up your inventory file, where you have to mention the necessary passwords (admin_password, pg_password, rabbitmq_password) in the inventory file.
55+
56+
Step 3: Now, as the Tower setup playbook script uses the inventory file, it has to be invoked as ./setup.sh from the path where you unpacked the Tower installer tarball.
57+
58+
./setup.sh
59+
Step 4: Once you are done setting up the Tower, use the web browser to access the Tower server and view the Tower login screen, wherein you have to enter the username and password, to access the Tower Dashboard.
60+
61+
Create a User
62+
To create a user, go the settings option and then choose the User tab. Once you enter the User tab, click on the Add option to add a new User. Mention the details required and then click on Save.
63+
64+
Create an Inventory
65+
Now, create an Inventory, by just clicking on the Inventories option and then going to the Add option.
66+
67+
Once you click on the Add option, mention all the details required like the name, description, organization and then click on Save.
68+
69+
Create a Host
70+
To create a host, go the Inventories tab and choose the inventory to which you want to add hosts. Then choose the Hosts tab and click on Add Hosts. Here I want to add hosts for the inventory that was created above. Once the details are mentioned, click on Save.
71+
72+
Create a Credential
73+
After creating hosts, create a credential by going to the settings options, and then choose the Credentials tab. After that, go to the Add option and mention the details. Once you are done, mentioning the details, click on Save.
74+
75+
Setting up a Project
76+
There are two ways to access a simple playbook, either you can do it manually or by specifying a link from a Github repository.
77+
78+
In this blog, I am going to access the project manually.
79+
80+
Accessing a Manually created Playbook
81+
For accessing a manually created playbook, you first have to create a playbook and then set up the project.
82+
83+
So, follow the below steps and start creating a playbook.
84+
85+
Use command line console as a root user and create a directory for your project on the Tower server file system, in which to store your Ansible playbooks for this project.
86+
87+
Now, make a new project directory by creating it on the Tower filesystem under the Project Base Path directory, located by default in “/var/lib/awx/projects/”. Here the new directory is DEMO.
88+
89+
Now, let’s start setting up a project.
90+
91+
To set up a project use your web browser, create the new project by clicking on the Projects link at the top of the Tower Dashboard and click on the Add button.
92+
93+
Once you click on the Add button, you will be redirected to a page wherein you have to fill in details such as Name and Description of Project. Then, set the SCM type to be Manual, and for the Playbook Directory, select a value which corresponds to the subdirectory you created and then click on Save.
94+
95+
Create a Job Template
96+
Now, let’s create a Job Template, by going to the Job Template tab and then clicking on the Add button. Once you click on the Add button, you will be re-directed to the page where you have to fill in the details such as Name, Description, Inventory name, Project, Playbooks, Credentials.
97+
98+
Launch a Job
99+
From the Job Templates overview screen, click the Launch button(rocket symbol) to run the Job Template. When you launch the job you can clearly see at the end of the output that the message has been printed.

0 commit comments

Comments
 (0)