Accueil  > Dev  > Ansible  >  ConfigPoste

Description

Installation et configuration de tous les packages utiles pour mes postes Linux (Debian, Kali et Fedora) via un script Bash exécutant un playbook Ansible.

Personnalisation des thêmes et de la session utilisateur.

 

Démarrage

Chargement des différents Playbooks

- hosts: all
  become: true
  vars_files:
    - vars/main.yml
    - vars/vscode.yml

  roles:
    - base
    - dev
    - ops
    - fw

 

Installation des Packages de base

Les packages de base :

# Installation des Packages de base

- name: Installation des paquets de base DEBIAN
  apt:
    name: "{{item.name}}"
    state: present
  with_items:
    - { name: "zsh" }
    - { name: "git" }
    - { name: "ansible" }
    - { name: "acl" }
    - { name: "apt-transport-https" }
    - { name: "software-properties-common" }
    - { name: "htop" }
    - { name: "iftop" }
    - { name: "bpytop" }
    - { name: "bc" }
    - { name: "build-essential" }
    - { name: "ca-certificates" }
    - { name: "curl" }
    - { name: "dirmngr" }
    - { name: "exfat-fuse" }
    - { name: "gnupg2" }
    - { name: "libavcodec-extra" }
    - { name: "lsb-release" }
    - { name: "libffi-dev" }
    - { name: "libssl-dev" }
    - { name: "libkrb5-dev" }
    - { name: "krb5-user" }
    - { name: "python3-pip" }
    - { name: "python3-dev" }
    - { name: "python3-setuptools" }
    - { name: "python3-wheel" }
    - { name: "python3-psutil" }
    - { name: "thunderbird" }
    - { name: "chromium" }
    - { name: "gimp" }
    - { name: "gparted" }
    - { name: "iotop" }
    - { name: "atop" }
    - { name: "keepassxc" }
    - { name: "net-tools" }
    - { name: "remmina" }
    - { name: "remmina-plugin-rdp" }
    - { name: "remmina-plugin-secret" }
    - { name: "vlc" }
    - { name: "conky" }
    - { name: "filezilla" }
    - { name: "gparted" }
    - { name: "firefox-esr-l10n-fr" }
    - { name: "thunderbird-l10n-fr" }
    - { name: "chromium-l10n" }
    - { name: "fonts-opensymbol" }
    - { name: "fonts-crosextra-carlito" }
    - { name: "fonts-powerline" }
  when: ansible_os_family == "Debian"

# Installation des Packages de base
- name: Installation des paquets de base RedHat
  yum:
    name: "{{item.name}}"
    state: present
  with_items:
    - { name: "gnome-tweaks" }
    - { name: "zsh" }
    - { name: "git" }
    - { name: "ansible" }
    - { name: "apt-transport-https" }
    - { name: "htop" }
    - { name: "iftop" }
    - { name: "bpytop" }
    - { name: "bc" }
    - { name: "ca-certificates" }
    - { name: "curl" }
    - { name: "dirmngr" }
    - { name: "gnupg2" }
    - { name: "python3-pip" }
    - { name: "python3-setuptools" }
    - { name: "python3-wheel" }
    - { name: "python3-psutil" }
    - { name: "thunderbird" }
    - { name: "chromium" }
    - { name: "gimp" }
    - { name: "gparted" }
    - { name: "iotop" }
    - { name: "atop" }
    - { name: "keepassxc" }
    - { name: "net-tools" }
    - { name: "remmina" }
    - { name: "conky" }
    - { name: "filezilla" }
    - { name: "gparted" }
  when: ansible_os_family == "RedHat"

# Configuration des themes, icones
- name: Fichier des icones
  unarchive:
    src: "icons.tar.gz"
    dest: "/usr/share/"
  when: ansible_os_family == "RedHat"

- name: Fichier des themes
  unarchive:
    src: "themes.tar.gz"
    dest: "/usr/share/"
  when: ansible_os_family == "RedHat"

- name: Fichier zshrc Root
  copy:
    src: "zshrc"
    dest: "/root/.zshrc"
    owner: "root"
    group: "root"

- name: Fichier bashrc Root
  copy:
    src: "bashrc"
    dest: "/root/.bashrc"
    owner: "root"
    group: "root"

# Copie et création de la tache Cron pour MAJ auto
# - name: script de lancement de ansible
#   template:
#     src: Mirim.sh.j2
#     dest: /usr/bin/Mirim.sh
#     owner: root
#     group: root
#     mode: 0755

# - cron:
#     name: lancement de ansible-pull le matin
#     weekday: "*"
#     minute: "0"
#     hour: "20"
#     user: root
#     job: "/bin/bash /usr/bin/Mirim.sh"

- name: Rotation de log sur ansible.log
  copy:
    src: logrotate_ansible
    dest: /etc/logrotate.d/ansible
  when: ansible_os_family == "Debian"

# Personnalisation de la session
- name: Copie du fichier WallPaper
  copy:
    src: michael.png
    dest: /usr/share/backgrounds/michael.png
    owner: root
    group: root
# Personnalisation de la session
- name: Copie du fichier WallPaper
  copy:
    src: tourist.png
    dest: /usr/share/backgrounds/tourist.png
    owner: root
    group: root

- name: Install Teamviewver
  yum:
    name: http://download.teamviewer.com/download/linux/teamviewer.x86_64.rpm
    state: present
    disable_gpg_check: yes
    validate_certs: no
    skip_broken: yes
  when: ansible_os_family == "RedHat"

- name: Install OnblyOffice
  yum:
    name: https://download.onlyoffice.com/install/desktop/editors/linux/onlyoffice-desktopeditors.x86_64.rpm
    state: present
    disable_gpg_check: yes
    validate_certs: no
    skip_broken: yes
  when: ansible_os_family == "RedHat"

- name: Install OnblyOffice
  yum:
    name: https://launchpad.net/veracrypt/trunk/1.25.9/+download/veracrypt-1.25.9-CentOS-8-x86_64.rpm
    state: present
    disable_gpg_check: yes
    validate_certs: no
    skip_broken: yes
  when: ansible_os_family == "RedHat"

- name: Git Clone PowerLine
  git:
    repo: https://github.com/b-ryan/powerline-shell.git
    dest: /root/powerline
    # single_branch: yes
    version: master

- name: Installation Powerline
  ansible.builtin.script: /root/powerline/setup.py install
  args:
    executable: python3
    chdir: /root/powerline

- name: Script Utilisateur michael
  import_tasks: user.yml
  vars:
    utilisateur: "michael"
    shell: "bash"
- name: Script Utilisateur tourist
  import_tasks: user.yml
  vars:
    utilisateur: "tourist"
    shell: "zsh"
  when: ansible_os_family == "Debian"
- name: Script Utilisateur tourist
  import_tasks: user.yml
  vars:
    utilisateur: "tron"
    shell: "zsh"
  when: ansible_os_family == "Debian"

 

 

Création des utilisateurs

Fichiers Utilisateurs

# Création du Compte {{ utilisateur }}
- name: Creation du Compte Utilisateur {{ utilisateur }}
  user:
    name: "{{ utilisateur }}"
    password: "{{ password }}"
    groups: # Empty by default, here we give it some groups
      - audio
      - dialout
    state: present
    shell: /bin/{{ shell }}
    system: no # Defaults to no
    createhome: yes # Defaults to yes
    home: /home/{{ utilisateur }} # Defaults to /home/<username>
    generate_ssh_key: yes
    ssh_key_bits: 4096
    ssh_key_file: .ssh/id_rsa

- name: Autorisation de  '{{ utilisateur }}'  pour Sudo sans mot de passe
  lineinfile:
    dest: /etc/sudoers
    state: present
    regexp: "^{{ utilisateur }}"
    line: "{{ utilisateur }} ALL=(ALL) NOPASSWD: ALL"
    validate: "visudo -cf %s"

# Icone de l'utilisateur {{ utilisateur }}
- name: Verification de l'icon de {{ utilisateur }}
  stat:
    path: /var/lib/AccountsService/icons/{{ utilisateur }}
  register: profile_picture

- name: Téléchargement de l'icone
  become: true
  get_url:
    url: https://michael.mirim.fr/wp-content/uploads/2023/09/{{ utilisateur }}.png
    dest: /var/lib/AccountsService/icons/{{ utilisateur }}
    force: true
  #when: profile_picture.stat.checksum != 'd402e1effc8030039576856525b378743c53664b'

- name: Copie du fichier {{ utilisateur }}
  copy:
    src: utilisateur
    dest: /var/lib/AccountsService/users/{{ utilisateur }}

- name: mise à jour de l'icone du profil
  become: true
  lineinfile:
    path: /var/lib/AccountsService/users/{{ utilisateur }}
    regexp: "^Icon="
    line: "Icon=/var/lib/AccountsService/icons/{{ utilisateur }}"

# Copie des Fichiers configuration Git et Bash
- name: Fichier de configuration git
  copy:
    src: "gitconfig"
    dest: "/home/{{ utilisateur }}/.gitconfig"
    owner: "{{ utilisateur }}"
    group: "{{ utilisateur }}"

- name: Fichier zshrc
  copy:
    src: "zshrc"
    dest: "/home/{{ utilisateur }}/.zshrc"
    owner: "{{ utilisateur }}"
    group: "{{ utilisateur }}"

- name: Fichier bashrc
  copy:
    src: "bashrc"
    dest: "/home/{{ utilisateur }}/.bashrc"
    owner: "{{ utilisateur }}"
    group: "{{ utilisateur }}"

- name: Création du répertoire .ssh
  ignore_errors: yes
  file:
    path: /home/{{ utilisateur }}/.ssh
    state: directory
    owner: "{{ utilisateur }}"
    group: "{{ utilisateur }}"
    mode: "0700"
    recurse: yes
- name: Fichier de configuration ssh
  copy:
    src: "config"
    dest: "/home/{{ utilisateur }}/.ssh/config"
    owner: "{{ utilisateur }}"
    group: "{{ utilisateur }}"

- name: set wallpaper {{ utilisateur }}
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/desktop/background/picture-uri"
    value: "'file:///usr/share/backgrounds/{{ utilisateur }}.png'"
  ignore_errors: yes

- name: set Theme
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/desktop/interface/gtk-theme"
    value: "'Kali-Light'"

- name: set Theme Icon
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/desktop/interface/icon-theme"
    value: "'Flat-Remix-Blue-Light'"

- name: set wallpaper position
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/desktop/background/picture-options"
    value: "'zoom'"

- name: set Theme shell
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/shell/extensions/user-theme/name"
    value: "'Kali-Light'"

# Configuration du Terminal
- name: Terminal cache menubar
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/default-show-menubar"
    value: "false"

- name: Terminal cache scrollbar
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/scrollbar-policy"
    value: "'never'"

- name: Terminal theme-colors
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/use-theme-colors"
    value: "true"

- name: Terminal background-transparency-percent
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/background-transparency-percent"
    value: 5

- name: Terminal background-transparency-percent
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/use-system-font"
    value: "true"

- name: Terminal default-size-columns
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/default-size-columns"
    value: "123"

- name: Terminal font
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/font"
    value: "'Monospace 9'"

- name: Terminal cursor-shape
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/cursor-shape"
    value: "'underline'"

- name: Terminal Profil Name
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/visible-name"
    value: "'Mirim'"

- name: Terminal bgcolor
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/background-color"
    value: "'rgb(0,43,54)'"

- name: Terminal fgcolor
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/foreground-color"
    value: "'rgb(131,148,150)'"

- name: Ajout des icones du menu DEBIAN {{ utilisateur }}
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/shell/favorite-apps"
    value: "['org.gnome.Terminal.desktop', 'org.gnome.Nautilus.desktop', 'keepassxc.desktop']"
#    value: "['org.gnome.Terminal.desktop', 'org.gnome.Nautilus.desktop', 'keepassxc.desktop', 'chromium.desktop', 'firefox-esr.desktop', 'thunderbird.desktop', 'filezilla.desktop', 'kali-msfconsole.desktop', 'wireshark.desktop', 'kali-burpsuite.desktop', 'cherrytree.desktop']"
- name: Refresh font list
  shell: fc-cache -fv
  tags:
    - fonts
  when: ansible_os_family == "Debian"

- name: Ajout des icones du menu REDHAT
  become_user: "{{ utilisateur }}"
  dconf:
    key: "/org/gnome/shell/favorite-apps"
    value: "['org.gnome.Terminal.desktop', 'org.gnome.Nautilus.desktop', 'mozilla-thunderbird.desktop', 'firefox.desktop', 'chromium-browser.desktop', 'org.gnome.gedit.desktop', 'chromium.desktop', 'code.desktop', 'filezilla.desktop', 'org.keepassxc.KeePassXC.desktop']"
- name: Refresh font list
  shell: fc-cache -fv
  tags:
    - fonts
  when: ansible_os_family == "RedHat"

 

Installation de vsCode

Fichier :

- name: Add Apt-Keys
  apt_key:
    url: "{{item.name}}"
    state: present
  with_items:
    - { name: "https://packages.microsoft.com/keys/microsoft.asc" }
    - { name: "https://packages.sury.org/php/apt.gpg" }
  when: ansible_os_family == "Debian"

- name: Add Repos
  apt_repository:
    repo: "{{item.name}}"
    filename: "{{item.filename}}"
    state: present
  with_items:
    - {
        name: "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main",
        filename: "vscode",
      }
    - {
        name: "deb [arch=amd64] https://packages.sury.org/php/ {{ debian_version }} main",
        filename: "sury",
      }
  when: ansible_os_family == "Debian"

 

Installation des outils de développement

Fichier 

# - name: Attente PHP
#   pause:
#     minutes: 2

- name: Add Apt-Keys
  apt_key:
    url: "{{item.name}}"
    state: present
  with_items:
    - { name: "https://packages.microsoft.com/keys/microsoft.asc" }
    - { name: "https://packages.sury.org/php/apt.gpg" }
  when: ansible_os_family == "Debian"

- name: Add Repos
  apt_repository:
    repo: "{{item.name}}"
    filename: "{{item.filename}}"
    state: present
  with_items:
    - {
        name: "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main",
        filename: "vscode",
      }
    - {
        name: "deb [arch=amd64] https://packages.sury.org/php/ {{ debian_version }} main",
        filename: "sury",
      }
  when: ansible_os_family == "Debian"

- name: Import remi GPG key.
  rpm_key:
    key: "{{ remi_repo_gpg_key_url }}"
    state: present
  when: ansible_os_family == "RedHat"

- name: Install remi repo.
  yum:
    name: "{{ remi_repo_url }}"
    state: present
    disable_gpg_check: yes
    validate_certs: no
    skip_broken: yes
  when: ansible_os_family == "RedHat"

- name: enable remi-php
  ini_file:
    dest: /etc/yum.repos.d/remi.repo
    section: remi
    option: enabled
    value: 1
  when: ansible_os_family == "RedHat"

- name: Import vscode key
  rpm_key:
    state: present
    key: https://packages.microsoft.com/keys/microsoft.asc
  when: ansible_os_family == "RedHat"

- name: Add repository
  yum_repository:
    name: epel
    description: EPEL YUM repo
    baseurl: https://packages.microsoft.com/yumrepos/vscode/
  when: ansible_os_family == "RedHat"

# Installation des Packages de base
- name: Installation des paquets de base
  apt:
    name: "{{item.name}}"
    state: present
  with_items:
    - { name: 'php' }
    - { name: 'php-fpm' }
    - { name: 'php-mysql' }
    - { name: 'php-gd' }
    - { name: 'php-zip' }
    - { name: 'php-xml' }
    - { name: 'php-mbstring' }
    - { name: 'php-xdebug' }
    - { name: 'php-apcu' }
    - { name: "phpmyadmin" }
    - { name: "npm" }
    - { name: "nodejs" }
  when: ansible_os_family == "Debian"

# Installation des Packages de base
- name: Installation des paquets de base
  yum:
    name: "{{item.name}}"
    state: present
  with_items:
    - { name: "composer" }
    - { name: "httpd" }
    - { name: "php74-php" }
    - { name: "php74-php-fpm" }
    - { name: "php74-php-mysql" }
    - { name: "php74-php-gd" }
    - { name: "php74-php-zip" }
    - { name: "php74-php-xml" }
    - { name: "php74-php-mbstring" }
    - { name: "php74-php-xdebug" }
    - { name: "php74-php-apcu" }
    - { name: "php80-php" }
    - { name: "php80-php-fpm" }
    - { name: "php80-php-mysql" }
    - { name: "php80-php-gd" }
    - { name: "php80-php-zip" }
    - { name: "php80-php-xml" }
    - { name: "php80-php-mbstring" }
    - { name: "php80-php-xdebug" }
    - { name: "php80-php-apcu" }
    - { name: "php81-php" }
    - { name: "php81-php-fpm" }
    - { name: "php81-php-mysql" }
    - { name: "php81-php-gd" }
    - { name: "php81-php-zip" }
    - { name: "php81-php-xml" }
    - { name: "php81-php-mbstring" }
    - { name: "php81-php-xdebug" }
    - { name: "php81-php-apcu" }
    - { name: "php82-php" }
    - { name: "php82-php-fpm" }
    - { name: "php82-php-mysqlnd" }
    - { name: "php82-php-gd" }
    - { name: "php82-php-zip" }
    - { name: "php82-php-xml" }
    - { name: "php82-php-mbstring" }
    - { name: "php82-php-xdebug" }
    - { name: "php82-php-apcu" }
    - { name: "phpmyadmin" }
    - { name: "npm" }
    - { name: "nodejs" }
  when: ansible_os_family == "RedHat"

- name: Create Symbolic link
  file:
    src: /usr/share/phpmyadmin/
    dest: /var/www/html/phpmyadmin
    state: link
  ignore_errors: yes
  when: ansible_os_family == "Debian"

- name: Create Symbolic link
  file:
    src: /usr/share/phpMyAdmin/
    dest: /var/www/html/phpmyadmin
    state: link
  when: ansible_os_family == "RedHat"

- name: Give writable mode to http folder
  ignore_errors: yes
  file:
    path: /var/www/html
    state: directory
    mode: "0755"
    owner: www-data
    group: www-data
    recurse: yes
  when: ansible_os_family == "Debian"

- name: Give writable mode to http folder
  ignore_errors: yes
  file:
    path: /var/www/html
    state: directory
    mode: "0755"
    owner: apache
    group: apache
    recurse: yes
  when: ansible_os_family == "RedHat"

- name: ensure apache service is start
  service:
    name: apache2
    state: started
    enabled: yes
  when: ansible_os_family == "Debian"

- name: install mysql
  apt:
    name:
      - mariadb-server
      - python3-mysqldb # for mysql_db and mysql_user modules
    state: present
    update_cache: yes
  when: ansible_os_family == "Debian"

- name: ensure apache service is start
  service:
    name: httpd
    state: started
    enabled: yes
  when: ansible_os_family == "RedHat"

- name: install mysql
  yum:
    name:
      - mariadb-server
      - python3-mysqlclient
    state: present
    update_cache: yes
  when: ansible_os_family == "RedHat"

- name: Create MySQL client config
  copy:
    dest: "/root/.my.cnf"
    content: |
      [client]
      user=root
      password="{{ mysql_password }}"
    mode: 0400

- name: Allow external MySQL connexions (1/2)
  lineinfile:
    path: /etc/mysql/mariadb.conf.d/50-server.cnf
    regexp: "^skip-external-locking"
    line: "# skip-external-locking"
  notify: Restart mariadb
  when: ansible_os_family == "Debian"

- name: Allow external MySQL connexions (2/2)
  lineinfile:
    path: /etc/mysql/mariadb.conf.d/50-server.cnf
    regexp: "^bind-address"
    line: "# bind-address"
  notify: Restart mariadb
  when: ansible_os_family == "Debian"

- name: ensure mariadb service is start
  service:
    name: mariadb
    state: started
    enabled: yes

- name: "Create {{ mysql_user }} with all privileges"
  mysql_user:
    name: "{{ mysql_user }}"
    password: "{{ mysql_password }}"
    priv: "*.*:ALL"
    #host: "{{ webserver_host }}"
    state: present
    login_user: root
    login_password: "{{ root_password }}"
    login_unix_socket: /var/run/mysqld/mysqld.sock
  notify: Restart mariadb
  ignore_errors: yes
  when: ansible_os_family == "Debian"

- name: Download postman
  unarchive:
    src: https://dl.pstmn.io/download/latest/linux64
    dest: /opt
    creates: /opt/Postman
    remote_src: yes

- name: Create postman symlink
  file:
    src: /opt/Postman/Postman
    dest: /usr/bin/postman
    state: link

- name: Installation Symfony
  shell:  /usr/bin/wget https://get.symfony.com/cli/installer -O - | bash
  # shell: /usr/bin/curl -sL https://get.symfony.com/cli/installer | bash -
  # shell: /usr/bin/curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.rpm.sh' | sudo -E bash
  when: ansible_os_family == "RedHat"
  # warn: false

- name: Installation Symfony
  # shell:  /usr/bin/wget https://get.symfony.com/cli/installer -O - | bash
  shell: /usr/bin/curl -sL https://get.symfony.com/cli/installer | bash -
  # shell: /usr/bin/curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.rpm.sh' | sudo -E bash
  when: ansible_os_family == "Debian"
  # warn: false

# Installation des Packages de base
- name: Installation des paquets de base
  yum:
    name: "{{item.name}}"
    state: present
  with_items:
    - { name: "symfony-cli" }
  when: ansible_os_family == "RedHat"

- name: copy symfony exec
  copy:
    src: /root/.symfony5/bin/symfony
    dest: /usr/local/bin/symfony
    mode: 0755
  when: ansible_os_family == "Debian"

- name: Install packages
  package:
    name: "{{item.name}}"
    state: present
  with_items:
    - { name: "code" }

- name: Script Utilisateur michael
  import_tasks: user.yml
  vars:
    utilisateur: "michael"
    shell: "bash"
- name: Script Utilisateur tourist
  import_tasks: user.yml
  vars:
    utilisateur: "tourist"
    shell: "zsh"
  when: ansible_os_family == "Debian"
- name: Script Utilisateur tourist
  import_tasks: user.yml
  vars:
    utilisateur: "tron"
    shell: "zsh"
  when: ansible_os_family == "Debian"

 

Installation des Outils OPS

Fichier :

# Installation des Packages de base
- name: Install OPS paquets
  apt:
    name: '{{item.name}}'
    state: present
  with_items:
    - { name: 'minicom' }
    - { name: 'tftpd-hpa' }
  when: ansible_os_family == "Debian"

# Installation des Packages de base
- name: Install OPS paquets
  yum:
    name: '{{item.name}}'
    state: present
  with_items:
    - { name: 'minicom' }
    - { name: 'tftp-server' }
  when: ansible_os_family == "RedHat"

- name: Fichier Minicom
  copy:
    src: "minirc.dfl"
    dest: "/etc/minicom/minirc.dfl"
    owner: "root"
    group: "root"
  when: ansible_os_family == "Debian"

- name: Fichier Minicom
  copy:
    src: "minirc.dfl"
    dest: "/etc/minirc.dfl"
    owner: "root"
    group: "root"
  when: ansible_os_family == "RedHat"

- name: Création du répertoire TFTP
  file:
    path: /tftpboot
    state: directory
    owner: nobody
    group: nogroup
    mode: "0777"
    recurse: yes
  when: ansible_os_family == "Debian"

- name: Création du répertoire TFTP
  file:
    path: /tftpboot
    state: directory
    owner: nobody
    group: nobody
    mode: "0777"
    recurse: yes
  when: ansible_os_family == "RedHat"

 

Script Bash

 


#!/bin/bash
### VARIABLES ###
ANSIBLE_PATH="/etc/ansible";
TMP_PATH="/tmp/MirimAnsible";
### SCRIPT ###
if [ -f /usr/bin/dnf ]; then
/usr/bin/dnf install -y ansible git
fi
if [ -f /usr/bin/apt ]; then
/usr/bin/apt install -y ansible git
fi
if [ ! -d $ANSIBLE_PATH ];then
echo "Création du $ANSIBLE_PATH !";
/usr/bin/mkdir $ANSIBLE_PATH;
fi
if [ ! -d $TMP_PATH ];then
echo "Création du $TMP_PATH !";
/usr/bin/mkdir $TMP_PATH;
fi
/usr/bin/echo '['${HOSTNAME:0:10}']' > $TMP_PATH/hosts
/usr/bin/echo $HOSTNAME >> $TMP_PATH/hosts
/usr/bin/sudo /usr/bin/cp $TMP_PATH/hosts /etc/ansible/
/usr/bin/chmod 777 $ANSIBLE_PATH/hosts
# Si l'application python apt nest pas installé
/bin/cd $TMP_PATH
# Lancement de la commande de lancement d'Ansible.
ansible-pull --sleep 10 --checkout=main --directory=$TMP_PATH/ansible --url=https://user:password@git.mirim.fr/xxx/ConfigPoste.git main.yml
/usr/bin/rm -Rf $TMP_PATH $TMP_PATH/ansible

 

Variables

Fichier de variables

password: "password"
mysql_user: "mysql_user"
mysql_password: "password"
mysql_dbname: "dbname"
root_password: "password"
debian_version: "bookworm"
remi_repo_url: "https://rpms.remirepo.net/fedora/remi-release-{{ ansible_distribution_major_version }}.rpm"
remi_repo_gpg_key_url: "https://rpms.remirepo.net/RPM-GPG-KEY-remi2022"

 

Publié le
Modifié le