-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ansible-Task-1
90 lines (74 loc) · 1.69 KB
/
Ansible-Task-1
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
89
90
Task - 01: Anisble -> Configure Docker -> setup httpd server & start
===================================================================
Steps :
1.Ansible Host File
`````````````````````````````
# vim /etc/ansible/ansible.cfg
[defaults]
inventory = /etc/myhosts.txt
host_key_checking=false
2.Ansible Configuration File
```````````````````````````````````````
# vim /etc/myhosts.txt
[dockerhost]
<ip> ansible_ssh_user=root ansible_ssh_pass=redhat
3.Ping
``````````
# ansible dockerhost -m ping
4.Main Yml File
````````````````````````
# vim dockerhost.yml
- hosts: dockerhost
gather_facts: false
tasks:
- name: configure yum repository for docker
yum_repository:
name: dockerrepo
baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/
description: my docker repo
enabled: true
gpgcheck: no
- name: install docker tool
command: "yum install docker-ce -y --nobest"
- name: install python36
package:
name: python36
state: present
- name: install docker-py module
pip:
name: docker-py
- name: create a directory
file:
path: /root/Task1
state: directory
- name: copy contents
copy:
src: "index.html"
dest: "/root/Task1"
ignore_errors: yes
- name: start docker service
service:
name: "docker"
state: started
enabled: yes
- name: image pull
docker_image:
name: httpd
source: pull
- name: run the container
docker_container:
name: mywebserver
image: httpd
state: started
detach: true
interactive: true
ports:
- "8181:80"
volumes:
- /root/Task1/:/var/www/html/
5.Run Playbook
`````````````````````````
# ansible-playbook docker.yml
6.Check From Browser
````````````````````````````````
<ip>:8181