community.general.gitlab_project (8.5.0) — module

Creates/updates/deletes GitLab Projects

Authors: Werner Dijkerman (@dj-wasabi), Guillaume Martinez (@Lunik)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

When the project does not exist in GitLab, it will be created.

When the project does exists and O(state=absent), the project will be deleted.

When changes are made to the project, the project will be updated.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create GitLab Project
  community.general.gitlab_project:
    api_url: https://gitlab.example.com/
    api_token: "{{ api_token }}"
    name: my_first_project
    group: "10481470"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete GitLab Project
  community.general.gitlab_project:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    name: my_first_project
    state: absent
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create GitLab Project in group Ansible
  community.general.gitlab_project:
    api_url: https://gitlab.example.com/
    validate_certs: true
    api_username: dj-wasabi
    api_password: "MySecretPassword"
    name: my_first_project
    group: ansible
    issues_enabled: false
    merge_method: rebase_merge
    wiki_enabled: true
    snippets_enabled: true
    import_url: http://git.example.com/example/lab.git
    initialize_with_readme: true
    state: present
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: get the initial root password
  ansible.builtin.shell: |
    grep 'Password:' /etc/gitlab/initial_root_password | sed -e 's/Password\: \(.*\)/\1/'
  register: initial_root_password
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a GitLab Project using a username/password via oauth_token
  community.general.gitlab_project:
    api_url: https://gitlab.example.com/
    api_username: root
    api_password: "{{ initial_root_password }}"
    name: my_second_project
    group: "10481470"

Inputs

    
name:
    description:
    - The name of the project.
    required: true
    type: str

path:
    description:
    - The path of the project you want to create, this will be server_url/<group>/path.
    - If not supplied, name will be used.
    type: str

group:
    description:
    - Id or the full path of the group of which this projects belongs to.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Create or delete project.
    - Possible values are present and absent.
    type: str

topics:
    description:
    - A topic or list of topics to be assigned to a project.
    - It is compatible with old GitLab server releases (versions before 14, correspond
      to C(tag_list)).
    elements: str
    type: list
    version_added: 6.6.0
    version_added_collection: community.general

api_url:
    description:
    - The resolvable endpoint for the API.
    type: str

ca_path:
    description:
    - The CA certificates bundle to use to verify GitLab server certificate.
    type: str
    version_added: 8.1.0
    version_added_collection: community.general

username:
    description:
    - Used to create a personal project under a user's name.
    type: str
    version_added: 3.3.0
    version_added_collection: community.general

api_token:
    description:
    - GitLab access token with API permissions.
    type: str

import_url:
    description:
    - Git repository which will be imported into gitlab.
    - GitLab server needs read access to this git repository.
    required: false
    type: str

visibility:
    aliases:
    - visibility_level
    choices:
    - private
    - internal
    - public
    default: private
    description:
    - V(private) Project access must be granted explicitly for each user.
    - V(internal) The project can be cloned by any logged in user.
    - V(public) The project can be cloned without any authentication.
    type: str

avatar_path:
    description:
    - Absolute path image to configure avatar. File size should not exceed 200 kb.
    - This option is only used on creation, not for updates.
    type: path
    version_added: 4.2.0
    version_added_collection: community.general

description:
    description:
    - An description for the project.
    type: str

lfs_enabled:
    default: false
    description:
    - Enable Git large file systems to manages large files such as audio, video, and graphics
      files.
    required: false
    type: bool
    version_added: 2.0.0
    version_added_collection: community.general

api_password:
    description:
    - The password to use for authentication against the API.
    type: str

api_username:
    description:
    - The username to use for authentication against the API.
    type: str

merge_method:
    choices:
    - ff
    - merge
    - rebase_merge
    default: merge
    description:
    - What requirements are placed upon merges.
    - Possible values are V(merge), V(rebase_merge) merge commit with semi-linear history,
      V(ff) fast-forward merges only.
    type: str
    version_added: 1.0.0
    version_added_collection: community.general

wiki_enabled:
    default: true
    description:
    - If an wiki for this project should be available or not.
    type: bool

api_job_token:
    description:
    - GitLab CI job token for logging in.
    type: str
    version_added: 4.2.0
    version_added_collection: community.general

squash_option:
    choices:
    - never
    - always
    - default_off
    - default_on
    description:
    - Squash commits when merging.
    type: str
    version_added: 3.4.0
    version_added_collection: community.general

ci_config_path:
    description:
    - Custom path to the CI configuration file for this project.
    type: str
    version_added: 3.7.0
    version_added_collection: community.general

default_branch:
    description:
    - The default branch name for this project.
    - For project creation, this option requires O(initialize_with_readme=true).
    - For project update, the branch must exist.
    - Supports project's default branch update since community.general 8.0.0.
    type: str
    version_added: 4.2.0
    version_added_collection: community.general

issues_enabled:
    default: true
    description:
    - Whether you want to create issues or not.
    - Possible values are true and false.
    type: bool

validate_certs:
    default: true
    description:
    - Whether or not to validate SSL certs when supplying a HTTPS endpoint.
    type: bool

api_oauth_token:
    description:
    - GitLab OAuth token for logging in.
    type: str
    version_added: 4.2.0
    version_added_collection: community.general

packages_enabled:
    description:
    - Enable GitLab package repository.
    type: bool
    version_added: 3.4.0
    version_added_collection: community.general

snippets_enabled:
    default: true
    description:
    - If creating snippets should be available or not.
    type: bool

builds_access_level:
    choices:
    - private
    - disabled
    - enabled
    description:
    - V(private) means that repository CI/CD is allowed only to project members.
    - V(disabled) means that repository CI/CD is disabled.
    - V(enabled) means that repository CI/CD is enabled.
    type: str
    version_added: 6.2.0
    version_added_collection: community.general

forking_access_level:
    choices:
    - private
    - disabled
    - enabled
    description:
    - V(private) means that repository forks is allowed only to project members.
    - V(disabled) means that repository forks are disabled.
    - V(enabled) means that repository forks are enabled.
    type: str
    version_added: 6.2.0
    version_added_collection: community.general

monitor_access_level:
    choices:
    - private
    - disabled
    - enabled
    description:
    - V(private) means that monitoring health is allowed only to project members.
    - V(disabled) means that monitoring health is disabled.
    - V(enabled) means that monitoring health is enabled.
    type: str
    version_added: 6.4.0
    version_added_collection: community.general

releases_access_level:
    choices:
    - private
    - disabled
    - enabled
    description:
    - V(private) means that accessing release is allowed only to project members.
    - V(disabled) means that accessing release is disabled.
    - V(enabled) means that accessing release is enabled.
    type: str
    version_added: 6.4.0
    version_added_collection: community.general

initialize_with_readme:
    default: false
    description:
    - Will initialize the project with a default C(README.md).
    - Is only used when the project is created, and ignored otherwise.
    type: bool
    version_added: 4.0.0
    version_added_collection: community.general

merge_requests_enabled:
    default: true
    description:
    - If merge requests can be made or not.
    - Possible values are true and false.
    type: bool

shared_runners_enabled:
    description:
    - Enable shared runners for this project.
    type: bool
    version_added: 3.7.0
    version_added_collection: community.general

environments_access_level:
    choices:
    - private
    - disabled
    - enabled
    description:
    - V(private) means that deployment to environment is allowed only to project members.
    - V(disabled) means that deployment to environment is disabled.
    - V(enabled) means that deployment to environment is enabled.
    type: str
    version_added: 6.4.0
    version_added_collection: community.general

feature_flags_access_level:
    choices:
    - private
    - disabled
    - enabled
    description:
    - V(private) means that feature rollout is allowed only to project members.
    - V(disabled) means that feature rollout is disabled.
    - V(enabled) means that feature rollout is enabled.
    type: str
    version_added: 6.4.0
    version_added_collection: community.general

infrastructure_access_level:
    choices:
    - private
    - disabled
    - enabled
    description:
    - V(private) means that configuring infrastructure is allowed only to project members.
    - V(disabled) means that configuring infrastructure is disabled.
    - V(enabled) means that configuring infrastructure is enabled.
    type: str
    version_added: 6.4.0
    version_added_collection: community.general

allow_merge_on_skipped_pipeline:
    description:
    - Allow merge when skipped pipelines exist.
    type: bool
    version_added: 3.4.0
    version_added_collection: community.general

container_registry_access_level:
    choices:
    - private
    - disabled
    - enabled
    description:
    - V(private) means that container registry is allowed only to project members.
    - V(disabled) means that container registry is disabled.
    - V(enabled) means that container registry is enabled.
    type: str
    version_added: 6.2.0
    version_added_collection: community.general

remove_source_branch_after_merge:
    description:
    - Remove the source branch after merge.
    type: bool
    version_added: 3.4.0
    version_added_collection: community.general

security_and_compliance_access_level:
    choices:
    - private
    - disabled
    - enabled
    description:
    - V(private) means that accessing security and complicance tab is allowed only to
      project members.
    - V(disabled) means that accessing security and complicance tab is disabled.
    - V(enabled) means that accessing security and complicance tab is enabled.
    type: str
    version_added: 6.4.0
    version_added_collection: community.general

only_allow_merge_if_pipeline_succeeds:
    description:
    - Only allow merges if pipeline succeeded.
    type: bool
    version_added: 3.4.0
    version_added_collection: community.general

only_allow_merge_if_all_discussions_are_resolved:
    description:
    - All discussions on a merge request (MR) have to be resolved.
    type: bool
    version_added: 3.4.0
    version_added_collection: community.general

Outputs

error:
  description: the error message returned by the GitLab API.
  returned: failed
  sample: '400: path is already in use'
  type: str
msg:
  description: Success or failure message.
  returned: always
  sample: Success
  type: str
project:
  description: API object.
  returned: always
  type: dict
result:
  description: json parsed response from the server.
  returned: always
  type: dict