From 1335619a5f581282157a6520c5c92179d43b7897 Mon Sep 17 00:00:00 2001 From: William Date: Sat, 2 Jul 2022 15:24:45 +0200 Subject: [PATCH] Passage du nom du host en CLI. --- .gitignore | 1 - README.md | 18 ++++++++---------- hosts.example.ini | 7 ------- playbooks/app-install.yml | 2 +- playbooks/app-start.yml | 2 +- playbooks/app-stop.yml | 2 +- playbooks/db-create.yml | 2 +- 7 files changed, 12 insertions(+), 22 deletions(-) delete mode 100644 hosts.example.ini diff --git a/.gitignore b/.gitignore index 064317d..daa9006 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /playbook.retry -/hosts.ini /*.json diff --git a/README.md b/README.md index abbedcc..a34748c 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,11 @@ Available playbooks: + app-start + app-stop -Start by copy then change values of hosts example file : - -```bash -$ cp hosts.example.ini hosts.ini -``` - -Then create a file `vars.json` who contain : +First create a file `vars.json` who contain : ```json { + "working_dir": "/home/vagrant/test", "container_name": "myapp", "repository": "https://git.example.com/vendor/app.git", "version": "master", @@ -38,7 +33,8 @@ Then create a file `vars.json` who contain : Then run a playbook: ```bash -$ ansible-playbook -i hosts.ini -e @vars.json playbooks/app-install.yml +HOSTNAME=vps.example.com +$ ansible-playbook -i $HOSTNAME, -e ansible_python_interpreter=/usr/bin/python3 -e @vars.json playbooks/app-install.yml ``` ## Manage database @@ -47,10 +43,11 @@ Available playbooks: + db-create -First create a file `dbvars.json` who contain : +First create a file `vars.json` who contain : ```json { + "ansible_python_interpreter": "/usr/bin/python3", "container_name": "myappdb", "envvars": { "MYSQL_ROOT_PASSWORD": "superpassword", @@ -64,5 +61,6 @@ First create a file `dbvars.json` who contain : Then run a playbook: ```bash -$ ansible-playbook -i hosts.ini -e @dbvars.json playbooks/db-create.yml +HOSTNAME=vps.example.com +$ ansible-playbook -i $HOSTNAME, -e ansible_python_interpreter=/usr/bin/python3 -e @vars.json playbooks/db-create.yml ``` diff --git a/hosts.example.ini b/hosts.example.ini deleted file mode 100644 index d4783d6..0000000 --- a/hosts.example.ini +++ /dev/null @@ -1,7 +0,0 @@ -[webservers] -example.com - -[webservers:vars] -ansible_python_interpreter=/usr/bin/python3 - -working_dir=/var/apps diff --git a/playbooks/app-install.yml b/playbooks/app-install.yml index 71bb355..50ab68f 100755 --- a/playbooks/app-install.yml +++ b/playbooks/app-install.yml @@ -1,6 +1,6 @@ --- - name: Install app - hosts: webservers + hosts: all become: yes tasks: diff --git a/playbooks/app-start.yml b/playbooks/app-start.yml index 31630a3..506f0a4 100644 --- a/playbooks/app-start.yml +++ b/playbooks/app-start.yml @@ -1,6 +1,6 @@ --- - name: Start app - hosts: webservers + hosts: all become: yes tasks: diff --git a/playbooks/app-stop.yml b/playbooks/app-stop.yml index 8cb7fbe..25391eb 100644 --- a/playbooks/app-stop.yml +++ b/playbooks/app-stop.yml @@ -1,6 +1,6 @@ --- - name: Start app - hosts: webservers + hosts: all become: yes tasks: diff --git a/playbooks/db-create.yml b/playbooks/db-create.yml index 075db1e..fbed661 100644 --- a/playbooks/db-create.yml +++ b/playbooks/db-create.yml @@ -1,6 +1,6 @@ --- - name: Create mysql database - hosts: webservers + hosts: all become: yes tasks: