Skip to content

Commit

Permalink
Merge branch '2-refactor-vars' into 'master'
Browse files Browse the repository at this point in the history
✅Resolve "refactor vars"

Closes TheRojam#2 and sylvainar#9

See merge request lydra/yunohost/ansible-yunohost!3
  • Loading branch information
cchaudier committed Oct 12, 2021
2 parents 4d9d81f + b76b876 commit f6c6f1d
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 91 deletions.
75 changes: 75 additions & 0 deletions README-FR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ansible-yunohost
[🇬🇧 English version](README.md)

Deployez Yunohost avec Ansible !

## Prérequis

Aucun.

## Role Variables
Les variables par défaut sont disponibles dans `default/main.yml` cependant il est nécessaire de les surcharger selon vos besoins en termes de domaines, d'utilisateurs et d'applications sur Yunohost.

## Exemple de Variables
```yml
---
# Debian 10 script only.
ynh_install_script_url: https://install.yunohost.org

ynh_admin_password: MYINSECUREPWD_PLZ_OVERRIDE_THIS

# The list of domains.
ynh_main_domain: domain.tld
ynh_extra_domains:
- forum.domain.tld
- wiki.domain.tld
ynh_ignore_dyndns_server: False

# The list of Yunohost users.
ynh_users:
- name: user1
pass: MYINSECUREPWD_PLZ_OVERRIDE_THIS
firstname: Jane
lastname: Doe
mail_domain: domain.tld

# The list of Yunohost apps.
ynh_apps:
- label: WikiJS # Label is important, it's a reference for the Playbook.
link: wikijs # It can be the name of an official app or a git repo link.
args: # Provide args. Domain and pah are mandatory, for other args read manifest.json of app.
domain: wiki.domain.tld
path: /
admin: user1
is_public: no
- label: Discourse
link: discourse
args:
domain: forum.domain.tld
path: /
admin: user1
is_public: yes
```
## Dépendances
Aucune.
## Exemple de Playbook
```yml
---
- name: Install Yunohost on Debian Server
hosts: all
become: True
pre_tasks:
- name: Update all packages and index
ansible.builtin.apt:
upgrade: dist
update_cache: yes

roles:
- ansible-yunohost
```
## License
GPL-3.0
99 changes: 51 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,76 @@
ansible-yunohost
=========
# ansible-yunohost
[🇫🇷 French version](README-FR.md)

Deploy Yunohost with Ansible!

Requirements
------------
## Requirements

None.

Role Variables
--------------
## Role Variables
Default variables are available in `default/main.yml` however it is necessary to override them according to your needs for Yunohost domains, users and apps.

Example of Variables:
## Example of Variables
```yml
yunohost:
# Link to the install script
install_script_url: https://raw.githubusercontent.com/YunoHost/install_script/master/install_yunohost
# The main domain, then a list of other domains.
domain: example.com
extra_domains:
- example2.com
- example3.com
# Yunohost admin password
password: MYINSECUREPWD_PLZ_OVERRIDE_THIS
# If you don't want to use a noho.st url
ignore_dyndns: False
# The list of apps you want to install.
apps:
- label: Tiny Tiny RSS # Label is important, it's a reference for the Playbook.
link: ttrss # It can be the name of an official app or a github link
args: # Provide here args. Path and domain are mandatory, other args depend of the app (cf manifest.json of app).
path: /ttrss
domain: example.com
# The list of frontend users.
users:
- name: user1 # user which uses the default domain for its account
pass: p@ssw0rd
firstname: Jane
lastname: Doe
domain: '{{ domain }}'
- name: user2 # user which uses the first extra_domain for its account
pass: p@ssw0rd
firstname: John
lastname: Doe
domain: '{{ extra_domain.[1] }}'
---
# Debian 10 script only.
ynh_install_script_url: https://install.yunohost.org

ynh_admin_password: MYINSECUREPWD_PLZ_OVERRIDE_THIS

# The list of domains.
ynh_main_domain: domain.tld
ynh_extra_domains:
- forum.domain.tld
- wiki.domain.tld
ynh_ignore_dyndns_server: False

# The list of Yunohost users.
ynh_users:
- name: user1
pass: MYINSECUREPWD_PLZ_OVERRIDE_THIS
firstname: Jane
lastname: Doe
mail_domain: domain.tld

# The list of Yunohost apps.
ynh_apps:
- label: WikiJS # Label is important, it's a reference for the Playbook.
link: wikijs # It can be the name of an official app or a git repo link.
args: # Provide args. Domain and pah are mandatory, for other args read manifest.json of app.
domain: wiki.domain.tld
path: /
admin: user1
is_public: no
- label: Discourse
link: discourse
args:
domain: forum.domain.tld
path: /
admin: user1
is_public: yes
```
Dependencies
------------
## Dependencies
None.
Example Playbook
----------------
## Example Playbook
```yml
- name: Provision servers
---
- name: Install Yunohost on Debian Server
hosts: all
remote_user: root
become: True
pre_tasks:
- name: Update all packages and index
ansible.builtin.apt:
upgrade: dist
update_cache: yes

roles:
- { role: sylvainar.yunohost }
- ansible-yunohost
```
License
-------
## License
GPL-3.0
33 changes: 25 additions & 8 deletions default/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
yunohost:
install_script_url: https://install.yunohost.org/
domain: example.com
extra_domains: ~
password: MYINSECUREPWD_PLZ_OVERRIDE_THIS
ignore_dyndns: False
apps: ~
users: ~
---
# Debian 10 script only.
ynh_install_script_url: https://install.yunohost.org

ynh_admin_password: MYINSECUREPWD_PLZ_OVERRIDE_THIS

# The list of Yunohost domains.
ynh_main_domain: domain.tld
ynh_extra_domains: null
ynh_ignore_dyndns_server: False

# The list of Yunohost users.
ynh_users: null
# - name: user1
# pass: p@ssw0rd
# firstname: Jane
# lastname: Doe
# mail_domain: domain.tld

# The list of Yunohost apps.
ynh_apps: null
# - label: Tiny Tiny RSS # Label is important, it's a reference for the Playbook.
# link: ttrss # It can be the name of an official ynh app or a git repo link
# args: # Provide args here. Domain and path are mandatory, other args depend on the app (cf manifest.json of app).
# domain: domain.tld
# path: /ttrss
15 changes: 9 additions & 6 deletions tasks/apps.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
---
- name: List currently installed apps
ansible.builtin.shell: yunohost app map --output-as json
register: yunohost_installed_apps_raw
register: ynh_installed_apps_raw
changed_when: False

- name: Format json of apps
ansible.builtin.set_fact: yunohost_installed_apps="{{ yunohost_installed_apps_raw.stdout | from_json }}"
ansible.builtin.set_fact: ynh_installed_apps="{{ ynh_installed_apps_raw.stdout | from_json }}"

- name: Install apps
ansible.builtin.shell: yunohost app install {{ item.link }} --label "{{ item.label }}" --args "{% for key, value in item.args.items() %}{{key}}={{value}}{% if not loop.last %}&{% endif %}{% endfor %}"
with_items: "{{ yunohost.apps }}"
when: item.label not in yunohost_installed_apps.values()
- name: Install yunohost apps
ansible.builtin.shell: yunohost app install {{ item.link }} \
--label "{{ item.label }}" \
--args "{% for key, value in item.args.items() %}{{ key }}={{ value
}}{% if not loop.last %}&{% endif %}{% endfor %}"
with_items: "{{ ynh_apps }}"
when: item.label not in ynh_installed_apps.values()
8 changes: 4 additions & 4 deletions tasks/domains.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: List currently installed domains
ansible.builtin.shell: yunohost domain list --output-as json
register: yunohost_installed_domains_raw
register: ynh_installed_domains_raw
changed_when: False

- name: Format json of domains
ansible.builtin.set_fact: yunohost_installed_domains="{{ yunohost_installed_domains_raw.stdout | from_json }}"
ansible.builtin.set_fact: ynh_installed_domains="{{ ynh_installed_domains_raw.stdout | from_json }}"

- name: Create domains
ansible.builtin.shell: yunohost domain add {{ item }}
with_items: "{{ yunohost.extra_domains }}"
when: item not in yunohost_installed_domains.domains
with_items: "{{ ynh_extra_domains }}"
when: item not in ynh_installed_domains.domains
39 changes: 19 additions & 20 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,42 @@

- name: Test if Yunohost is already installed
ansible.builtin.stat: path=/etc/yunohost/installed
register: yunohost_file_install
register: ynh_file_install

- name: Download install script
- name: Download Yunohost install script
ansible.builtin.get_url:
url: "{{ yunohost.install_script_url }}"
url: "{{ ynh_install_script_url }}"
dest: /tmp/install_yunohost.sh
mode: 700
when: yunohost_file_install.stat.exists == False
when: ynh_file_install.stat.exists == False

- name: Launch script
- name: Launch Yunohost install script
ansible.builtin.command: /tmp/install_yunohost.sh -a
when: yunohost_file_install.stat.exists == False
when: ynh_file_install.stat.exists == False

- name: Launch postinsstall
- name: Launch Yunohost postinstall
ansible.builtin.shell: "
yunohost tools postinstall \
--domain {{ yunohost.domain }} \
--password {{ yunohost.password }} \
{% if yunohost.ignore_dyndns == True %} --ignore-dyndns {% endif %}
"
when: yunohost_file_install.stat.exists == False
--domain {{ ynh_main_domain }} \
--password {{ ynh_admin_password }} \
{% if ynh_ignore_dyndns_server == True %} --ignore-dyndns {% endif %}"
when: ynh_file_install.stat.exists == False

- name: Create domains
- name: Create extra domains
ansible.builtin.include: domains.yml
when: yunohost.extra_domains
when: ynh_extra_domains

- name: Run diagnosis # Required to install certificates
- name: Run first Yunohost diagnosis
ansible.builtin.shell: yunohost diagnosis run

- name: Install certificates
- name: Install domain certificates
ansible.builtin.shell: yunohost domain cert-install
changed_when: False

- name: Add users
- name: Add Yunohost users
ansible.builtin.include: users.yml
when: yunohost.users
when: ynh_users

- name: Install apps
- name: Install Yunohost apps
ansible.builtin.include: apps.yml
when: yunohost.apps
when: ynh_apps
10 changes: 5 additions & 5 deletions tasks/users.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
- name: List users
ansible.builtin.shell: yunohost user list --output-as json
register: yunohost_registered_users_raw
register: ynh_registered_users_raw
changed_when: False

- name: Format json of users
ansible.builtin.set_fact: yunohost_registered_users="{{ yunohost_registered_users_raw.stdout | from_json }}"
ansible.builtin.set_fact: ynh_registered_users="{{ ynh_registered_users_raw.stdout | from_json }}"

- name: Create missing users
- name: Create missing Yunohost users
ansible.builtin.shell: |
yunohost user create {{ item.name }} \
-f {{ item.firstname }} \
-l {{ item.lastname }} \
-d {{ item.mail_domain }} \
-p {{ item.pass }}
loop: "{{ yunohost.users }}"
when: item.name not in yunohost_registered_users.users.keys()
loop: "{{ ynh_users }}"
when: item.name not in ynh_registered_users.users.keys()

0 comments on commit f6c6f1d

Please sign in to comment.