Compare commits
3 Commits
transcaffe
...
85d3999faf
| Author | SHA1 | Date | |
|---|---|---|---|
|
85d3999faf
|
|||
|
ab4b7bafe7
|
|||
|
55f7ea3c40
|
@@ -2,15 +2,8 @@
|
||||
|
||||
## Overview
|
||||
|
||||
This collection contains roles focused on various components around CI/CD, including
|
||||
automation servers like Jenkins, its agents or vaguely related components like caching
|
||||
proxies and artifact registries.
|
||||
|
||||
## Roles
|
||||
|
||||
- [`jenkins`](roles/jenkins/README.md): Deploy [jenkins](https://jenkins.io), the self-proclaimed 'leading open source automation server'.
|
||||
- [`jenkins_inbound_agent`](roles/jenkins_inbound_agent/README.md): Deploy Jenkins 'inbound agent', formerly known as 'JNLP agent'.
|
||||
- [jenkins](roles/jenkins/README.md): Deploy [jenkins](https://jenkins.io), the self-proclaimed 'leading open source automation server'.
|
||||
|
||||
## License
|
||||
|
||||
[CNPLv7+](LICENSE.md): Cooperative Nonviolent Public License
|
||||
|
||||
@@ -12,7 +12,4 @@ build_ignore:
|
||||
- '*.tar.gz'
|
||||
repository: https://git.finally.coffee/finallycoffee/cicd
|
||||
issues: https://codeberg.org/finallycoffee/ansible-collection-cicd/issues
|
||||
tags:
|
||||
- cicd
|
||||
- ci
|
||||
- cd
|
||||
tags: []
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
---
|
||||
- name: Deploy 'Ara records ansible' API server
|
||||
hosts: "{{ ara_server_hosts | default('ara_server') }}"
|
||||
become: "{{ ara_become | default(false) }}"
|
||||
gather_facts: "{{ ara_gather_facts | default(false) }}"
|
||||
roles:
|
||||
- role: finallycoffee.cicd.ara
|
||||
@@ -17,9 +17,8 @@ class Jenkins:
|
||||
internal_dir: PathSpec
|
||||
server_url: str
|
||||
|
||||
def __init__(self, server_url, username, api_token):
|
||||
def __init__(self, server_url, api_token):
|
||||
self.server_url = server_url
|
||||
self.username = username
|
||||
self.api_token = api_token
|
||||
|
||||
def _log_in(self, username: str, password: str) -> (str, str):
|
||||
@@ -30,8 +29,7 @@ class Jenkins:
|
||||
|
||||
def get_node_jnlp(self, node_name) -> str:
|
||||
response = requests.get(
|
||||
f"{self.server_url}/manage/computer/{node_name}/slave-agent.jnlp",
|
||||
auth=(self.username, self.api_token),
|
||||
f"{self.server_url}/manage/computer/{node_name}/slave-agent.jnlp"
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.text
|
||||
@@ -41,6 +39,6 @@ class Jenkins:
|
||||
tree = ET.ElementTree(ET.fromstring(jnlp_info_raw))
|
||||
arguments = tree.findall("./application-desc/")
|
||||
(node_secret, node_name, _, work_dir, _, internal_dir, _, url) = [
|
||||
arg.text for arg in arguments[:8]
|
||||
arg.text for arg in arguments[:7]
|
||||
]
|
||||
return Jenkins.NodeInfo(url, node_name, node_secret, work_dir, internal_dir)
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
DOCUMENTATION = r"""
|
||||
---
|
||||
module: jenkins_node
|
||||
|
||||
short_description: Retrieve Jenkins node information
|
||||
# If this is part of a collection, you need to use semantic versioning,
|
||||
# i.e. the version is of the form "2.5.0" and not "2.4".
|
||||
version_added: "0.0.1"
|
||||
|
||||
description: This is my longer description explaining my test module.
|
||||
|
||||
options:
|
||||
name:
|
||||
description: The name of the jenkins node.
|
||||
required: true
|
||||
type: str
|
||||
aliases:
|
||||
- agent
|
||||
server:
|
||||
description: URL of the jenkins instance
|
||||
required: true
|
||||
type: str
|
||||
aliases:
|
||||
- server_url
|
||||
username:
|
||||
description: Username to use for authentication to jenkins
|
||||
required: true
|
||||
type: str
|
||||
aliases:
|
||||
- user
|
||||
api_token:
|
||||
description: Jenkins API token for the user
|
||||
required: true
|
||||
type: str
|
||||
author:
|
||||
- transcaffeine (@transcaffeine)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
# Pass in a message
|
||||
- name: Retrieve information about the jenkins node named 'my_jenkins_node_name'
|
||||
finallycoffee.cicd.jenkins_node_info:
|
||||
name: my_jenkins_node_name
|
||||
server: https://jenkins.example.org
|
||||
username: admin
|
||||
api_token: yoursecretapitokenhere
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
# These are examples of possible return values, and in general should use other names for return values.
|
||||
name:
|
||||
description: The name of the jenkins node
|
||||
type: str
|
||||
returned: always
|
||||
sample: 'jenkins-agent-jdk21-alpine'
|
||||
secret:
|
||||
description: The secret of the agent
|
||||
type: str
|
||||
returned: always
|
||||
sample: 'secretverylongstringwith64chars'
|
||||
work_dir:
|
||||
description: The local working directory of the jenkins agent
|
||||
type: str
|
||||
returned: always
|
||||
"""
|
||||
@@ -7,31 +7,91 @@ __metaclass__ = type # pylint: disable=C0103
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
from ansible_collections.finallycoffee.cicd.plugins.module_utils.Jenkins import Jenkins
|
||||
from ansible_collections.finallycoffee.cicd.plugins.module_utils.docs.jenkins_node_info import (
|
||||
DOCUMENTATION,
|
||||
EXAMPLES,
|
||||
RETURN,
|
||||
from ansible_collections.ansible.utils.plugins.module_utils.common.argspec_validate import ( # type: ignore
|
||||
AnsibleArgSpecValidator,
|
||||
)
|
||||
from ansible_collections.ansible.utils.plugins.modules.fact_diff import DOCUMENTATION # type: ignore
|
||||
|
||||
from plugins.module_utils.Jenkins import Jenkins
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
DOCUMENTATION = r"""
|
||||
---
|
||||
module: jenkins_node
|
||||
|
||||
short_description: Retrieve Jenkins node information
|
||||
# If this is part of a collection, you need to use semantic versioning,
|
||||
# i.e. the version is of the form "2.5.0" and not "2.4".
|
||||
version_added: "0.0.1"
|
||||
|
||||
description: This is my longer description explaining my test module.
|
||||
|
||||
options:
|
||||
name:
|
||||
description: The name of the jenkins node.
|
||||
required: true
|
||||
type: str
|
||||
server:
|
||||
description: URL of the jenkins instance
|
||||
required: true
|
||||
type: str
|
||||
api_token:
|
||||
description: Jenkins API token
|
||||
required: true
|
||||
type: str
|
||||
author:
|
||||
- transcaffeine (@transcaffeine)
|
||||
"""
|
||||
|
||||
EXAMPLES = r"""
|
||||
# Pass in a message
|
||||
- name: Test with a message
|
||||
my_namespace.my_collection.my_test:
|
||||
name: hello world
|
||||
|
||||
# pass in a message and have changed true
|
||||
- name: Test with a message and changed output
|
||||
my_namespace.my_collection.my_test:
|
||||
name: hello world
|
||||
new: true
|
||||
|
||||
# fail the module
|
||||
- name: Test failure of the module
|
||||
my_namespace.my_collection.my_test:
|
||||
name: fail me
|
||||
"""
|
||||
|
||||
RETURN = r"""
|
||||
# These are examples of possible return values, and in general should use other names for return values.
|
||||
name:
|
||||
description: The name of the jenkins node
|
||||
type: str
|
||||
returned: always
|
||||
sample: 'jenkins-agent-jdk21-alpine'
|
||||
secret:
|
||||
description: The secret of the agent
|
||||
type: str
|
||||
returned: always
|
||||
sample: 'secretverylongstringwith64chars'
|
||||
work_dir:
|
||||
description: The local working directory of the jenkins agent
|
||||
type: str
|
||||
returned: always
|
||||
"""
|
||||
|
||||
|
||||
def run_module():
|
||||
module_args = dict(
|
||||
name=dict(type="str", required=True, aliases=["node", "node_name"]),
|
||||
server=dict(type="str", required=True, aliases=["server_url", "url"]),
|
||||
username=dict(type="str", required=True, aliases=["user"]),
|
||||
api_token=dict(type="str", required=True, aliases=["password", "pass"]),
|
||||
name=dict(type="str", required=True),
|
||||
server=dict(type="str", required=True),
|
||||
api_token=dict(type="str", required=True),
|
||||
)
|
||||
result = dict(changed=False)
|
||||
result = dict(changed=False, original_message="", message="")
|
||||
module = AnsibleModule(argument_spec=module_args, supports_check_mode=True)
|
||||
|
||||
jenkins = Jenkins(
|
||||
module.params["server"], module.params["username"], module.params["api_token"]
|
||||
)
|
||||
jenkins = Jenkins(module.params["url"], module.params["token"])
|
||||
node = jenkins.get_node_info(module.params["name"])
|
||||
|
||||
result["name"] = node.name
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
ara_container_image_registry: "quay.io"
|
||||
ara_container_image_namespace: "recordsansible"
|
||||
ara_container_image_repository: "ara-api"
|
||||
ara_container_image_name: >-2
|
||||
{{ [
|
||||
ara_container_image_registry | default([], true),
|
||||
ara_container_image_namespace | default([], true),
|
||||
ara_container_image_repository
|
||||
] | flatten | join('/') }}
|
||||
ara_container_image_tag: ~ #TODO
|
||||
ara_container_image: >-2
|
||||
{{ [
|
||||
ara_container_image_name,
|
||||
ara_container_image_tag | default(ara_version, true)
|
||||
] | join(':') }}
|
||||
ara_container_image_source: "pull"
|
||||
ara_container_image_force_source: >-2
|
||||
{{ ara_container_image_tag | default(false, true) | bool }}
|
||||
ara_container_image_pull: "{{ ara_container_image_source == 'pull' }}"
|
||||
ara_container_image_force_pull: >-2
|
||||
{{ ara_container_image_pull and ara_container_image_force_source }}
|
||||
ara_container_image_state: "{{ ara_state }}"
|
||||
|
||||
ara_container_name: "ara-api"
|
||||
ara_container_state: >-2
|
||||
{{ (ara_state == 'present') | ternary('started', 'absent') }}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
ara_user: "ara"
|
||||
ara_version: "1.7.2"
|
||||
ara_state: "present"
|
||||
ara_deployment_method: "docker"
|
||||
@@ -1,8 +0,0 @@
|
||||
---
|
||||
ara_user_system: true
|
||||
ara_user_create_home: false
|
||||
ara_user_groups: ~
|
||||
ara_user_append: ~
|
||||
|
||||
ara_user_uid: "{{ ara_user_info.uid | default(ara_user) }}"
|
||||
ara_user_gid: "{{ ara_user_info.group | default(ara_user) }}"
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
- name: Ensure 'ara_state' is valid
|
||||
ansible.builtin.fail:
|
||||
msg: >-2
|
||||
Unsupported ara_state '{{ ara_state }}'.
|
||||
Supported states are {{ ara_states | map(quote) | join(', ') }}.
|
||||
when: ara_state not in ara_states
|
||||
|
||||
- name: Ensure 'ara_deployment_method' is valid
|
||||
ansible.builtin.fail:
|
||||
msg: >-2
|
||||
Unsupported ara_deployment_method '{{ ara_deployment_method }}'.
|
||||
Supported methods are {{ ara_deployment_methods | map(quote) | join(', ') }}.
|
||||
when: ara_deployment_method not in ara_deployment_methods
|
||||
@@ -1,12 +0,0 @@
|
||||
---
|
||||
- name: Ensure ara container image '{{ ara_container_image }}' is {{ ara_container_image_state }}
|
||||
community.docker.docker_image:
|
||||
name: "{{ ara_container_image }}"
|
||||
state: "{{ ara_container_image_state }}"
|
||||
source: "{{ ara_container_image_source }}"
|
||||
force_source: "{{ ara_container_image_force_source }}"
|
||||
|
||||
- name: Ensure ara container '{{ ara_container_name }}' is {{ ara_container_state }}
|
||||
community.docker.docker_container:
|
||||
name: "{{ ara_container_name }}"
|
||||
image: "{{ ara_container_image }}"
|
||||
@@ -1,12 +0,0 @@
|
||||
---
|
||||
- name: Ensure ara container image '{{ ara_container_image }}' is {{ ara_container_image_state }}
|
||||
containers.podman.podman_image:
|
||||
name: "{{ ara_container_image }}"
|
||||
state: "{{ ara_container_image_state }}"
|
||||
pull: "{{ ara_container_image_pull }}"
|
||||
force: "{{ ara_container_image_force_pull }}"
|
||||
|
||||
- name: Ensure ara container '{{ ara_container_name }}' is {{ ara_container_state }}
|
||||
containers.podman.podman_container:
|
||||
name: "{{ ara_container_name }}"
|
||||
image: "{{ ara_container_image }}"
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
- name: Ensure preconditions for ara role are met
|
||||
ansible.builtin.include_tasks:
|
||||
file: "check.yml"
|
||||
|
||||
- name: Ensure ara user '{{ ara_user }}' is {{ ara_state }}
|
||||
ansible.builtin.user:
|
||||
name: "{{ ara_user }}"
|
||||
state: "{{ ara_state }}"
|
||||
system: "{{ ara_user_system }}"
|
||||
create_home: "{{ ara_user_create_home }}"
|
||||
groups: "{{ ara_user_groups | default(omit, true) }}"
|
||||
append: "{{ ara_user_append | default(omit, true) }}"
|
||||
register: ara_user_info
|
||||
|
||||
- name: Deploy ara api server using {{ ara_deployment_method }}
|
||||
ansible.builtin.include_tasks:
|
||||
file: "deploy-{{ ara_deployment_method }}.yml"
|
||||
@@ -1,7 +0,0 @@
|
||||
---
|
||||
ara_states:
|
||||
- "present"
|
||||
- "absent"
|
||||
ara_deployment_methods:
|
||||
- "docker"
|
||||
- "podman"
|
||||
@@ -3,8 +3,8 @@ jenkins_user: "jenkins"
|
||||
jenkins_user_is_system: true
|
||||
jenkins_user_create_home: false
|
||||
jenkins_versions:
|
||||
lts: "2.516.1"
|
||||
weekly: "2.521"
|
||||
lts: "2.479.3"
|
||||
weekly: "2.496"
|
||||
jenkins_version_channel: "lts"
|
||||
jenkins_version: "{{ jenkins_versions[jenkins_version_channel] }}"
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ jenkins_agent_user_is_system: false
|
||||
jenkins_agent_user_uid: "{{ jenkins_agent_user_info.uid }}"
|
||||
jenkins_agent_user_gid: "{{ jenkins_agent_user_info.group }}"
|
||||
|
||||
jenkins_agent_version: "3341.v0766d82b_dec0-1"
|
||||
jenkins_agent_version: "3283.v92c105e0f819-8"
|
||||
|
||||
jenkins_agent_state: "present"
|
||||
jenkins_agent_deployment_method: "docker"
|
||||
|
||||
Reference in New Issue
Block a user