homework 9.4: fix playbook

This commit is contained in:
2022-08-31 09:54:33 +07:00
parent 605c94642c
commit 6eb86580b9
2 changed files with 69 additions and 16 deletions

View File

@@ -63,17 +63,26 @@
state: restarted
enabled: true
when: jenkins_installed is changed
- name: ensure github.com is a known host
lineinfile:
dest: ~/.ssh/known_hosts
create: yes
state: present
line: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
regexp: "^github\\.com"
tags:
- jenkins-master
- name: Prepare jenkins agent
hosts: jenkins_agents
become: true
become_user: "{{ jenkins_user_name }}"
tasks:
- name: Add master publickey into authorized_key
authorized_key:
user: "{{ jenkins_user_name }}"
state: present
key: "{{ hostvars['jenkins-master-01']['ssh_key_info']['ssh_public_key'] }}"
# - name: Add master publickey into authorized_key
# authorized_key:
# user: "{{ jenkins_user_name }}"
# state: present
# key: "{{ hostvars['jenkins-master-01']['ssh_key_info']['ssh_public_key'] }}"
- name: Create agent_dir
become_user: root
file:
@@ -92,21 +101,56 @@
yum:
name:
- git
- python3
- docker-ce
- docker-ce-cli
- containerd.io
- gcc
- openssl-devel
- bzip2-devel
- libffi-devel
- zlib-devel
- xz-devel
state: present
- name: Download python 3.8 distrib
ansible.builtin.get_url:
url: "https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tgz"
dest: "{{ jenkins_agent_dir }}/Python-3.8.12.tgz"
- name: Unpack python 3.8 distrib
ansible.builtin.unarchive:
src: "{{ jenkins_agent_dir }}/Python-3.8.12.tgz"
dest: "{{ jenkins_agent_dir }}"
remote_src: true
- name: Configure python 3.8
ansible.builtin.shell:
cmd: ./configure --enable-optimizations
chdir: "{{ jenkins_agent_dir }}/Python-3.8.12"
- name: Install python 3.8
become_user: root
ansible.builtin.shell:
cmd: make altinstall
chdir: "{{ jenkins_agent_dir }}/Python-3.8.12"
- name: Create symbolic link python3
become_user: root
ansible.builtin.file:
src: /usr/local/bin/python3.8
dest: /usr/local/bin/python3
state: link
- name: Create symbolic link pip3
become_user: root
ansible.builtin.file:
src: /usr/local/bin/pip3.8
dest: /usr/local/bin/pip3
state: link
- name: Update pip
become_user: root
pip:
executable: pip3
executable: /usr/local/bin/pip3
name: pip
extra_args: --upgrade
- name: Install Ansible
become_user: root
pip:
executable: pip3
executable: /usr/local/bin/pip3
name:
- selinux
- ansible<3.0
@@ -114,7 +158,7 @@
- name: Reinstall Selinux
become_user: root
pip:
executable: pip3
executable: /usr/local/bin/pip3
name:
- selinux
state: forcereinstall
@@ -149,5 +193,14 @@
timeout: 10
- name: Install pip molecule
ansible.builtin.pip:
executable: pip3
executable: /usr/local/bin/pip3
name: molecule
- name: ensure github.com is a known host
lineinfile:
dest: ~/.ssh/known_hosts
create: yes
state: present
line: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
regexp: "^github\\.com"
tags:
- jenkins-agent

View File

@@ -12,11 +12,11 @@
> 3. Запустить и проверить работоспособность.
> 4. Сделать первоначальную настройку.
[Playbook](./infrastructure/site.yml) для установки `jenkins`. Добавлена установка `molecule`
в сравнении с оригинальным содержимым.
// todo Доработать playbook для запуска добавления github.com в known_hosts
// todo Доработать playbook для установки python версии >= 3.8 (+pip)
[Playbook](./infrastructure/site.yml) для установки `jenkins`. Были сделаны следующие доработки в сравнении
с оригинальным `playbook`:
- На мастере и агенте `github.com` добавлен в `known_hosts` пользователя `jenkins`
- На агенте установлен `python3.8` из исходников
- Добавлена установка `molecule`
Запуск: