Skip to content

Instantly share code, notes, and snippets.

@coder4temp
Last active December 31, 2022 08:22
Show Gist options
  • Save coder4temp/97288d74484b03be1935d878290d6e3d to your computer and use it in GitHub Desktop.
Save coder4temp/97288d74484b03be1935d878290d6e3d to your computer and use it in GitHub Desktop.
ansible playbook redhat and debian
[defaults]
inventory = inventory
host_key_checking = False
---
- hosts: redhat #centos and redhat
gather_facts: False
pre_tasks:
- name: Install python for Ansible
raw: dnf install -y python3
register: output
changed_when: output.stdout != ""
tags: always
tasks:
- name: Install yum utils
yum:
name: yum-utils
state: present
- name: Install epel-release
shell: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
args:
executable: /bin/bash
- name: Install apps in redhat centos
yum:
name: ['epel-release', 'docker-ce', 'docker-ce-cli', 'containerd.io', 'docker-compose-plugin', 'containerd.io', 'byobu', 'htop', 'wget', 'curl', 'nano', 'zsh',
'git', 'util-linux-user']
state: present
- name: Start Docker
service:
name: docker
state: started
- name: Enable Docker
service:
name: docker
enabled: yes
- name: install ssh public key to remote ansible
authorized_key:
user: root
key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
- name: installing ohmyzsh
shell: echo Y | sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
args:
executable: /bin/bash
- name: change shell to zsh
shell: chsh -s $(which zsh)
args:
executable: /bin/bash
- name: git cloning zsh plugings
shell: git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions && git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
args:
executable: /bin/bash
- name: Ansible replace string example
shell: sed '73s/.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting )/' /root/.zshrc > /tmp/.zshrc && rm -rf /root/.zshrc && cp /tmp/.zshrc /root/.zshrc
args:
executable: /bin/bash
- hosts: debian #debian
gather_facts: False
pre_tasks:
- name: Install python for Ansible
raw: apt install -y python3
register: output
changed_when: output.stdout != ""
tags: always
tasks:
- name: Install apps in redhat centos
environment:
DEBIAN_FRONTEND: noninteractive
shell: apt -yqq install docker.io byobu htop wget curl nano zsh git
args:
executable: /bin/bash
- name: Start Docker
service:
name: docker
state: started
- name: Enable Docker
service:
name: docker
enabled: yes
- name: install ssh public key to remote ansible
authorized_key:
user: root
key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
- name: installing ohmyzsh
shell: echo Y | sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
args:
executable: /bin/bash
- name: change shell to zsh
shell: chsh -s $(which zsh)
args:
executable: /bin/bash
- name: git cloning zsh plugings
shell: git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions && git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
args:
executable: /bin/bash
- name: Ansible replace string example
shell: sed '73s/.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete)/' /root/.zshrc > /tmp/.zshrc && rm -rf /root/.zshrc && cp /tmp/.zshrc /root/.zshrc
args:
executable: /bin/bash
---
- hosts: debian
tasks:
- name: dependency provisioning
gather_facts: false
tasks:
raw: apt-get -y install python2 python3
- hosts: redhat
tasks:
- name: dependency provisioning
gather_facts: false
tasks:
raw: dnf -y install python2 python3
- hosts: redhat #centos and redhat
tasks:
- name: dependency provisioning
gather_facts: false
tasks:
- name: install python2
raw: sudo apt-get -y install python2 python3
- name: Install yum utils
yum:
name: yum-utils
state: present
- name: Install docker repositoy in alma linux
shell:
cmd: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- name: Install apps in redhat centos
yum:
name: "{{ item }}"
state: present
with_items:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
- containerd.io
- byobu
- htop
- wget
- curl
- nano
- zsh
- git
- util-linux-user
- name: Start Docker
service:
name: docker
state: started
- name: Enable Docker
service:
name: docker
enabled: yes
- hosts: debian #debian
tasks:
- name: Install apps in redhat centos
apt:
name: "{{ item }}"
state: present
with_items:
- docker.io
- byobu
- htop
- wget
- curl
- nano
- zsh
- git
- name: Start Docker
service:
name: docker
state: started
- name: Enable Docker
service:
name: docker
enabled: yes
- hosts: "*"
tasks:
- name: install ssh public key to remote ansible
authorized_key:
user: root
key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
- name: installing ohmyzsh
shell:
cmd: sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
- name: change shell to zsh
shell:
cmd: chsh -s $(which zsh)
---
- hosts: redhat #centos and redhat
tasks:
- name: Install yum utils
yum:
name: yum-utils
state: present
- name: Install docker repositoy in alma linux
shell:
cmd: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- name: Install apps in redhat centos
yum:
name: "{{ item }}"
state: present
with_items:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
- containerd.io
- byobu
- htop
- wget
- curl
- nano
- zsh
- git
- util-linux-user
- name: Start Docker
service:
name: docker
state: started
- name: Enable Docker
service:
name: docker
enabled: yes
- hosts: debian #debian
tasks:
- name: Install apps in redhat centos
apt:
name: "{{ item }}"
state: present
with_items:
- docker.io
- byobu
- htop
- wget
- curl
- nano
- zsh
- git
- name: Start Docker
service:
name: docker
state: started
- name: Enable Docker
service:
name: docker
enabled: yes
- hosts: "*"
tasks:
- name: install ssh public key to remote ansible
authorized_key:
user: root
key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
- name: installing ohmyzsh
shell:
cmd: sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
- name: change shell to zsh
shell:
cmd: chsh -s $(which zsh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment