Installez Ansible à l'avance, créez une clé avec ssh-keygen -t rsa afin de pouvoir vous connecter avec la clé.
Comment afficher les paramètres courants tels que la connexion
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
Installez simplement en utilisant la commande apt
nginx.yml
- hosts: web
  become: yes
  tasks:
  - name: "install nginx"
    apt:
      name: ['nginx']
      state: latest
Mémo de résultat d'exécution
$ 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   
Opération simple vérifier que le serveur nginx est en cours d'exécution
$ 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>
Opération qui s'installe simplement en utilisant apt
docker.yaml
- hosts: web
  become: yes
  tasks:
  - name: "install docker.io"
    apt:
      name: ['docker.io']
      state: latest
Résultat d'exécution
$ 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   
Confirmez que le docker est en cours d'exécution
$ sudo docker ps
[sudo]Identifiant Mot de passe: 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
        Recommended Posts