Showing posts with label Ansible. Show all posts
Showing posts with label Ansible. Show all posts

Friday, January 22, 2021

Ansible - create multiple directories

HOWTO

 

GitHub repo

 


 Create role

- name: Create /app/dave  dir
  become: true
  file:
    path: /app/dave
    state: directory
    owner: dave
    group: dave
    recurse: yes
    mode: '0755'

- name: Create /app/dave/  appl dirs
  file:
      path: "{{ item }}"
      owner: dave
      group: dave
      recurse: yes
  with_items:
        - /app/dave/opt/jboss
        - /app/dave/data/

Dir structure
[dave@dave devops-ansible]$ find create-dev-env/
create-dev-env/
create-dev-env/tasks
create-dev-env/tasks/main.yml

 

Call role 

Create file local.yml

---
- name: Configure local dev env
  hosts: localhost
  connection: local
  gather_facts: no
  roles:
    - dave-dev-env

 

Run playbook

ansible-playbook local.yml



Saturday, November 28, 2020

Install Jenkins via Ansible

HOWTO 


  • Install Jenkins using Galaxy role  https://training.galaxyproject.org/training-material/topics/admin/tutorials/jenkins/tutorial.html



Clone repository with playbook

https://github.com/dveselka/devops-ansible/tree/master/jenkins

[dave@dave ~]$ git clone https://github.com/dveselka/devops-ansible

Install Ansible Galaxy roles
[dave@dave ~]$ cd devops-ansible/
[dave@dave devops-ansible]$ cd jenkins/
[dave@dave jenkins]$ ls
create_jenkins.yml  dev_vars.yml  README.md  requirements.yml
[dave@dave jenkins]$ ansible-galaxy install -p roles -r requirements.yml
- downloading role 'java', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-java/archive/1.10.0.tar.gz
- extracting geerlingguy.java to /home/dave/devops-ansible/jenkins/roles/geerlingguy.java
- geerlingguy.java (1.10.0) was installed successfully
- downloading role 'jenkins', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-jenkins/archive/4.3.0.tar.gz
- extracting geerlingguy.jenkins to /home/dave/devops-ansible/jenkins/roles/geerlingguy.jenkins
- geerlingguy.jenkins (4.3.0) was installed successfully


Check Java version
[dave@dave jenkins]$ java -version
java version "11.0.9" 2020-10-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.9+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.9+7-LTS, mixed mode)



Run Ansible playbook
[dave@dave jenkins]$ ansible-playbook -K  create_jenkins.yml 
BECOME password: 
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Install Jenkins on localhost] *****************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.java : Include OS-specific variables for Fedora or FreeBSD.] **********************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.java : Include version-specific variables for CentOS/RHEL.] ***********************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : Include version-specific variables for Ubuntu.] ****************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : Include version-specific variables for Debian.] ****************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : Define java_packages.] *****************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.java : include_tasks] *************************************************************************************************************************************************************************
included: /home/dave/devops-ansible/jenkins/roles/geerlingguy.java/tasks/setup-RedHat.yml for localhost

TASK [geerlingguy.java : Ensure Java is installed.] *************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.java : include_tasks] *************************************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : include_tasks] *************************************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.java : Set JAVA_HOME if configured.] **********************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Include OS-Specific variables] ******************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Define jenkins_repo_url] ************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Define jenkins_repo_key_url] ********************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Define jenkins_pkg_url] *************************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : include_tasks] **********************************************************************************************************************************************************************
included: /home/dave/devops-ansible/jenkins/roles/geerlingguy.jenkins/tasks/setup-RedHat.yml for localhost

TASK [geerlingguy.jenkins : Ensure dependencies are installed.] *************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Ensure Jenkins repo is installed.] **************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Add Jenkins repo GPG key.] **********************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Download specific Jenkins version.] *************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Check if we downloaded a specific version of Jenkins.] ******************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Install our specific version of Jenkins.] *******************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Ensure Jenkins is installed.] *******************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : include_tasks] **********************************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : include_tasks] **********************************************************************************************************************************************************************
included: /home/dave/devops-ansible/jenkins/roles/geerlingguy.jenkins/tasks/settings.yml for localhost

TASK [geerlingguy.jenkins : Check if jenkins_init_file exists.] *************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Ensure jenkins_init_file exists.] ***************************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Modify variables in init file.] *****************************************************************************************************************************************************
changed: [localhost] => (item={'option': 'JENKINS_ARGS', 'value': '--prefix='})
changed: [localhost] => (item={'option': 'JENKINS_JAVA_OPTIONS', 'value': '-Xmx4096M'})

TASK [geerlingguy.jenkins : Ensure jenkins_home /var/lib/jenkins exists.] ***************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Set the Jenkins home directory.] ****************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Immediately restart Jenkins on init config changes.] ********************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Set HTTP port in Jenkins config.] ***************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Create custom init scripts directory.] **********************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Configure proxy config for Jenkins] *************************************************************************************************************************************************
skipping: [localhost]

RUNNING HANDLER [geerlingguy.jenkins : configure default users] *************************************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Immediately restart Jenkins on http or user changes.] *******************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Ensure Jenkins is started and runs on startup.] *************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Wait for Jenkins to start up before proceeding.] ************************************************************************************************************************************
FAILED - RETRYING: Wait for Jenkins to start up before proceeding. (60 retries left).
FAILED - RETRYING: Wait for Jenkins to start up before proceeding. (59 retries left).
FAILED - RETRYING: Wait for Jenkins to start up before proceeding. (58 retries left).
ok: [localhost]

TASK [geerlingguy.jenkins : Get the jenkins-cli jarfile from the Jenkins server.] *******************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : Remove Jenkins security init scripts after first startup.] **************************************************************************************************************************
changed: [localhost]

TASK [geerlingguy.jenkins : include_tasks] **********************************************************************************************************************************************************************
included: /home/dave/devops-ansible/jenkins/roles/geerlingguy.jenkins/tasks/plugins.yml for localhost

TASK [geerlingguy.jenkins : Get Jenkins admin password from file.] **********************************************************************************************************************************************
skipping: [localhost]

TASK [geerlingguy.jenkins : Set Jenkins admin password fact.] ***************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Create Jenkins updates directory.] **************************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Download current plugin updates from Jenkins update site.] **************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Remove first and last line from json file.] *****************************************************************************************************************************************
ok: [localhost]

TASK [geerlingguy.jenkins : Install Jenkins plugins using password.] ********************************************************************************************************************************************

PLAY RECAP ******************************************************************************************************************************************************************************************************
localhost                  : ok=34   changed=13   unreachable=0    failed=0    skipped=13   rescued=0    ignored=0   


Configure nodes 

https://www.howtoforge.com/tutorial/ubuntu-jenkins-master-slave/



Saturday, September 14, 2019

Postinstall tasks for Fedora using Ansible

Fedora Ansible tasks repo - various tasks

https://docs.fedoraproject.org/en-US/quick-docs/adding-or-removing-software-repositories-in-fedora/



https://github.com/fabaff/fedora-ansible

Code for example below
https://github.com/dveselka/devops-ansible/tree/master/fedora-postinstall

Create Ansible playbook

[dave@dave fedora-ansible-postinstall]$ find
.
./post_install.yml
./tasks
./tasks/rpmfusion.yml



---
- hosts: localhost
  become: yes
  vars:
    fedora_current: 30
  tasks:
    - include: tasks/rpmfusion.yml

Enable RPMFusion repository

---
- name: install the rpmfusion repo packages
  dnf:
    name: ['http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-{{ fedora_current }}.noarch.rpm', 
'http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-{{ fedora_current }}.noarch.rpm']
    state: present

Run Ansible playbook

sudo ansible-playbook post_install.yml -vv
Added Google Chrome installation task
sudo ansible-playbook post_install.yml 
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [localhost] ********************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************
ok: [localhost]

TASK [install the rpmfusion repo packages] ******************************************************************************************************************************
ok: [localhost]

TASK [install Fedora Workstation repositories] **************************************************************************************************************************
ok: [localhost]

TASK [install Google Chrome] ********************************************************************************************************************************************
ok: [localhost]

PLAY RECAP **************************************************************************************************************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0