Simple installation of nginx and Docker using ansible

Advance preparation

Install Ansible in advance, create a key with ssh-keygen -t rsa so that you can log in with the key.

Common setting

How to show common settings such as connection

inventory.yml


web:
  hosts:
    hostname
  vars:
    domain: helloworld.com
    ansible_user: username
    ansible_ssh_private_key_file: ~/.ssh/id_rsa
    ansible_sudo_pass: test_password

When installing nginx

Simply install using the apt command

nginx.yml


- hosts: web
  become: yes
  tasks:
  - name: "install nginx"
    apt:
      name: ['nginx']
      state: latest

Execution result memo

$ ansible-playbook -i inventory.yml nginx.yaml 

PLAY [web] ********************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************
ok: [hostname]

TASK [install nginx] **********************************************************************************************************************************************
changed: [hostname]

PLAY RECAP ********************************************************************************************************************************************************
hostname     : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Simple operation check that nginx server is running

$ curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Simple installation of docker

Just install using apt

docker.yaml


- hosts: web
  become: yes
  tasks:
  - name: "install docker.io"
    apt:
      name: ['docker.io']
      state: latest

Execution result

$ ansible-playbook -i inventory.yml docker.yaml 

PLAY [web] ********************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************
ok: [hostname]

TASK [install docker.io] ******************************************************************************************************************************************
changed: [hostname]

PLAY RECAP ********************************************************************************************************************************************************
hostname     : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Confirm that docker is running

$ sudo docker ps
[sudo]password for username: 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Recommended Posts

Simple installation of nginx and Docker using ansible
Docker installation and initialization
About simple operation of Docker
Latest docker installation (Ubuntu 20.04 and Ubuntu 20.10)
Installing and using Ansible on Ubuntu 16.04
Summary of Docker understanding by beginners ③ ~ Until proxying API using nginx ~
Deploy an image consisting of Tomcat, Java and MySQL using Ansible and Jenkins
[Challenge Docker from 0] Overview and terms of Docker
Docker installation
[docker] [nginx] Make a simple ALB with nginx
Implementation of tabs using TabLayout and ViewPager
Introduction of Docker Hub and commands Self-learning ①
Kaggle environment construction using official Docker and vscode
Introduction and basic usage of Simple Calendar gem
Docker on Ubuntu18.04 on WSL2 and VSCode installation instructions
A reminder of Docker and development environment construction
Support out of support in docker environment using centos6
Quick docker / nginx
Summary of frequently used commands in Rails and Docker
Easily build Redmine on Windows using WSL2 and Docker
Data management using Docker bindmount and tmpfs (personal memorandum)
Verification of the relationship between Docker images and containers
[Java10] Be careful of using var and generics together
Construction of data analysis environment using Docker (personal memorandum)
Send and receive simple messages using the Kafka component of the Apache Camel framework (Java DSL)