From 375f217ba205234d61fd3ca7455d1295e4fd4b6c Mon Sep 17 00:00:00 2001 From: nazunalika Date: Sun, 27 Mar 2022 17:53:47 -0700 Subject: [PATCH] Use ansible.builtin and add new adhocs --- adhoc-create-org.yml | 17 ++++++++++++- adhoc-create-team.yml | 34 +++++++++++++++++++++++++ adhoc-team-mod-members.yml | 28 ++++++++++++++++++++ role-gitea.yml | 11 +++++--- tasks/gitea/configure.yml | 2 +- tasks/gitea/install.yml | 52 +++++++++++++++++++------------------- tasks/gitea/theme.yml | 2 +- 7 files changed, 113 insertions(+), 33 deletions(-) create mode 100644 adhoc-create-team.yml create mode 100644 adhoc-team-mod-members.yml diff --git a/adhoc-create-org.yml b/adhoc-create-org.yml index 96748ef..0203f87 100644 --- a/adhoc-create-org.yml +++ b/adhoc-create-org.yml @@ -1,7 +1,10 @@ --- # This playbook is meant to be used with callable variables, like adhoc or AWX. # What: Creates an organization/group in Gitea, relying on the gitea collection -# What is expected: +# What is expected (at a minimum): +# -> gitea_api_user + gitea_api_password *OR* gitea_api_token +# -> gitea_org_name +# -> gitea_org_owner, optional (defaults to token or api user if not set) - name: Create Gitea Organization or Group hosts: all become: false @@ -12,4 +15,16 @@ # Optionally assign user as part of owner team # Remove automated account tasks: + - name: "Create organization" + lazyutilitynet.ansible_gitea.gitea_org: + api_url: "https://{{ gitea_basename }}" + api_username: "{{ gitea_api_user|default(omit) }}" + api_password: "{{ gitea_api_password|default(omit) }}" + api_token: "{{ gitea_api_token|default(omit) }}" + state: "{{ gitea_org_state|default('present') }}" + org_name: "{{ gitea_org_name }}" + location: "{{ gitea_org_location|default(omit) }}" + full_name: "{{ gitea_org_full_name|default(omit) }}" + owner: "{{ gitea_org_owner|default(omit) }}" + description: "{{ gitea_org_desc|default(omit) }}" ... diff --git a/adhoc-create-team.yml b/adhoc-create-team.yml new file mode 100644 index 0000000..7681e02 --- /dev/null +++ b/adhoc-create-team.yml @@ -0,0 +1,34 @@ +--- +# This playbook is meant to be used with callable variables, like adhoc or AWX. +# What: Creates an team in a Gitea Organization, relying on the gitea collection +# What is expected: +# -> gitea_api_user + gitea_api_password *OR* gitea_api_token +# -> gitea_org_name +# -> gitea_team_name +# -> gitea_state, present or absent (defaults to present) +# -> gitea_permission, none/read/write/admin (default read) +# -> gitea_permissions, this is a dictionary, cannot be paired with +# gitea_permission +- name: Create Gitea Team in an Organization or Group + hosts: all + become: false + vars_files: + - "vars/common.yml" + + # Create team + tasks: + - name: "Create team and Add Users" + lazyutilitynet.ansible_gitea.gitea_team: + api_url: "https://{{ gitea_basename }}" + api_username: "{{ gitea_api_user|default(omit) }}" + api_password: "{{ gitea_api_password|default(omit) }}" + api_token: "{{ gitea_api_token|default(omit) }}" + state: "{{ gitea_org_state|default('present') }}" + org_name: "{{ gitea_org_name }}" + name: "{{ gitea_team_name }}" + description: "{{ gitea_org_desc|default(omit) }}" + members: "{{ gitea_team_members|default(omit) }}" + permission: "{{ gitea_permission|default(omit) }}" + permissions: "{{ gitea_permissions|default(omit) }}" + member_action: "add" +... diff --git a/adhoc-team-mod-members.yml b/adhoc-team-mod-members.yml new file mode 100644 index 0000000..dd6fefd --- /dev/null +++ b/adhoc-team-mod-members.yml @@ -0,0 +1,28 @@ +--- +# This playbook is meant to be used with callable variables, like adhoc or AWX. +# What: Modifies a team in a Gitea Organization, relying on the gitea collection +# What is expected: +# -> gitea_api_user + gitea_api_password *OR* gitea_api_token +# -> gitea_org_name +# -> gitea_team_name +# -> gitea_team_members (in the form of a list) +# -> gitea_team_action, add or remove +- name: Create Gitea Team in an Organization or Group + hosts: all + become: false + vars_files: + - "vars/common.yml" + + # Create team + tasks: + - name: "Create team and Add Users" + lazyutilitynet.ansible_gitea.gitea_team: + api_url: "https://{{ gitea_basename }}" + api_username: "{{ gitea_api_user|default(omit) }}" + api_password: "{{ gitea_api_password|default(omit) }}" + api_token: "{{ gitea_api_token|default(omit) }}" + org_name: "{{ gitea_org_name }}" + name: "{{ gitea_team_name }}" + members: "{{ gitea_team_members }}" + member_action: "{{ gitea_team_action }}" +... diff --git a/role-gitea.yml b/role-gitea.yml index f7ea0aa..da51913 100644 --- a/role-gitea.yml +++ b/role-gitea.yml @@ -21,12 +21,15 @@ success_msg: "We are able to run on this node" fail_msg: "/etc/no-ansible exists - skipping run on this node" - - name: Enable the proper copr for gitea - command: "dnf copr enable nalika/gitea -y" - check_mode: false - changed_when: "1 != 1" + # name: Enable the proper copr for gitea + # command: "dnf copr enable nalika/gitea -y" + # check_mode: false + # changed_when: "1 != 1" roles: + - role: lazyutilitynet.ansible_gitea.gitea_install + state: present + - role: rockylinux.ipagetcert state: present when: gitea_web_config_certs_internal|bool diff --git a/tasks/gitea/configure.yml b/tasks/gitea/configure.yml index fd57711..ae424cf 100644 --- a/tasks/gitea/configure.yml +++ b/tasks/gitea/configure.yml @@ -1,7 +1,7 @@ --- # Configuration for gitea - name: Enable Gitea - service: + ansible.builtin.service: name: gitea state: started enabled: true diff --git a/tasks/gitea/install.yml b/tasks/gitea/install.yml index 0fb1d5f..58a1d8b 100644 --- a/tasks/gitea/install.yml +++ b/tasks/gitea/install.yml @@ -1,38 +1,38 @@ --- # Install gitea -- name: "Installing Gitea from COPR" - dnf: - name: gitea - state: present +# name: "Installing Gitea from COPR" +# dnf: +# name: gitea +# state: present # Install web front end -- name: "Installing httpd package and configuration" - dnf: - name: gitea-httpd - state: present - when: - - gitea_web_install == "httpd" - - gitea_web_config|bool +# name: "Installing httpd package and configuration" +# dnf: +# name: gitea-httpd +# state: present +# when: +# - gitea_web_install == "httpd" +# - gitea_web_config|bool -- name: "Installing nginx package and configuration" - dnf: - name: gitea-nginx - state: present - when: - - gitea_web_install == "nginx" - - gitea_web_config|bool +# name: "Installing nginx package and configuration" +# dnf: +# name: gitea-nginx +# state: present +# when: +# - gitea_web_install == "nginx" +# - gitea_web_config|bool -- name: "Installing caddy package and configuration" - dnf: - name: gitea-caddy - state: present - when: - - gitea_web_install == "caddy" - - gitea_web_config|bool +# name: "Installing caddy package and configuration" +# dnf: +# name: gitea-caddy +# state: present +# when: +# - gitea_web_install == "caddy" +# - gitea_web_config|bool # Setup CSS Themes - name: - file: + ansible.builtin.file: path: "/var/lib/gitea/custom/public/css" owner: git group: git diff --git a/tasks/gitea/theme.yml b/tasks/gitea/theme.yml index 676355d..aa054b2 100644 --- a/tasks/gitea/theme.yml +++ b/tasks/gitea/theme.yml @@ -1,6 +1,6 @@ --- - name: Deploy all theme files - copy: + ansible.builtin.copy: src: "var/lib/gitea/custom/public/css/{{ item }}" dest: "/var/lib/gitea/custom/public/css/{{ item }}" mode: '0644'