All Projects → clouddrove → ansible-commands

clouddrove / ansible-commands

Licence: MIT license
This repository is used to understand how to use ansible commands.

Projects that are alternatives of or similar to ansible-commands

Ansible Nginx Hardening
This Ansible role provides secure nginx configurations.
Stars: ✭ 180 (+650%)
Mutual labels:  playbook, role
ansible-haproxy
Ansible HAproxy role for Unified OpenStack Installer and others.
Stars: ✭ 35 (+45.83%)
Mutual labels:  playbook, role
Ansible Role Php
Ansible Role - PHP
Stars: ✭ 396 (+1550%)
Mutual labels:  playbook, role
Ansible Role Mysql
Ansible Role - MySQL
Stars: ✭ 826 (+3341.67%)
Mutual labels:  playbook, role
Ansible Mysql Hardening
This Ansible role provides security configuration for MySQL.
Stars: ✭ 132 (+450%)
Mutual labels:  playbook, role
Ansible Role Ruby
Ansible Role - Ruby
Stars: ✭ 77 (+220.83%)
Mutual labels:  playbook, role
Ansible Ssh Hardening
This Ansible role provides numerous security-related ssh configurations, providing all-round base protection.
Stars: ✭ 746 (+3008.33%)
Mutual labels:  playbook, role
Ansible Collection Hardening
This Ansible collection provides battle tested hardening for Linux, SSH, nginx, MySQL
Stars: ✭ 2,543 (+10495.83%)
Mutual labels:  playbook, role
faq
Русскоязычный проект помощи начинающим дедам-программистам 30+, 40+, 50+
Stars: ✭ 142 (+491.67%)
Mutual labels:  cheet-sheet, cheetsheet
ansible-role-dns
Install and configure dns on your system.
Stars: ✭ 39 (+62.5%)
Mutual labels:  playbook
ansible-role-dsvpn
Install and configure dsvpn on your system.
Stars: ✭ 18 (-25%)
Mutual labels:  playbook
ansible-role-php-versions
Ansible Role - PHP Versions
Stars: ✭ 78 (+225%)
Mutual labels:  role
ansible-role-elasticsearch-curator
Ansible Role - Elasticsearch Curator
Stars: ✭ 31 (+29.17%)
Mutual labels:  role
passbolt ansible
A complete (set of) playbook(s) to selfhost passbolt.
Stars: ✭ 15 (-37.5%)
Mutual labels:  playbook
ansible-role-glusterfs
Ansible Role - GlusterFS
Stars: ✭ 95 (+295.83%)
Mutual labels:  role
showme
Rapid diagnostic system status tool (performance monitoring, network scanning, mysql performance monitoring, kubectl status)
Stars: ✭ 24 (+0%)
Mutual labels:  playbook
openvpn
Build your own private VPN server. OpenVPN, Scramblesuit and DNS up in less then 5 minutes
Stars: ✭ 78 (+225%)
Mutual labels:  playbook
ansible-avd
Ansible Arista Validated Design
Stars: ✭ 134 (+458.33%)
Mutual labels:  playbook
ansible-taskrunner
Ansible Taskrunner - ansible-playbook wrapper with YAML-abstracted python click cli options!
Stars: ✭ 14 (-41.67%)
Mutual labels:  playbook
multi-master-kubernetes
Multi-master Kubernetes cluster on Exoscale
Stars: ✭ 65 (+170.83%)
Mutual labels:  playbook

Ansible commands

Software License

List of general purpose commands for Ansible management:

Installation

sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible
ansible --version

Inventory

Example of Inventory file

[mysql]
10.0.0.13 = Env=live EcType=mysql EcName=live-mysql-0-b Az=a Nr=0
[nginx]
10.0.0.17 = Env=live EcType=nginx EcName=live-nginx-0-b Az=a Nr=0

[live:children]
mysql
nginx

Check Connection

$ ansible -m ping <host>

Ad-Hoc Commands

Parallelism Shell Commands

ssh-agnet bash $ ssh-add ~/.ssh/id_rsa

Reboot remove server using anisble

ansible mysql -a "/sbin/reboot" -f 20

Run ansible using specific user

ansible nginx -a "/usr/bin/foo" -u anmolnagpal

Run ansible using specific user

ansible nginx -a "/usr/bin/foo" -u anmolnagpal

File Transfer

Transfer file to many servers

ansible nginx -m copy -a "src=/etc/anmol.txt dest=/tmp/anmol.txt"

Transfer file with specific ownership & permission

ansible nginx -m file -a "src=/etc/anmol.txt dest=/tmp/anmol.txt mode=600"
ansible nginx -m file -a "src=/etc/anmol.txt dest=/tmp/anmol.txt mode=600 owner=anmol gorup=anmol"

Create Directories

ansible nginx -m file -a "dest=/tmp/clouddrove mode=755 owner=anmol gorup=anmol stage=directory"

Delete Directories

ansible nginx -m file -a "dest=/tmp/clouddrove state=absent"

Manage Packages

Ensure package is installed, but doesn't get updated

ansible mysql -m apt -a "name=python state=present"

Ensure package is installed to a specific version

ansible mysql -m apt -a "name=python-2.6 state=present"

Ensure package is installed with latest version

ansible mysql -m apt -a "name=python state=latest"

Ensure package is installed is not installed

ansible mysql -m apt -a "name=python state=absent"

Manage Services

Ensure a service is started on all nginx servers

ansible nginx -m service -a "name=nginx state=started"

Restart service on all nginx servers

ansible nginx -m service -a "name=nginx state=restarted"

Ensure a service is stopped

ansible nginx -m service -a "name=nginx state=stopped"

Playbooks

Playbook: Update system (Debian based)

- hosts: local
  tasks:
    - name: Update system
      apt:
        update_cache: yes
        upgrade: yes
    - name: Remove dependencies
      apt:
        autoremove: yes
    - name: Remove useless packages from the cache
      apt:
        autoclean: yes

Sample Playbooks

- name: dpkg --configure -a
  shell: dpkg --configure -a
  tags:
    - dpkg

- name: install system pakcages and utils
  apt:
    name: "{{ item }}"
    state: latest
    update_cache: yes
    cache_valid_time: 5400
    allow_unauthenticated: yes
  with_items:
   - ntp
   - git
   - git-core
   - htop
   - vim
   - curl
   - unzip
   - jq
   - python-setuptools
   - python-dev
   - build-essential
  tags:
    - packages

Writing Playbooks

Create a playbook

- hosts: live-node-01
  become: true
  roles:
    - { role: common,    tags: [ 'common'    ] }
    - { role: docker,    tags: [ 'docker'    ] }
    - { role: jenkins,   tags: [ 'agent'     ] }
    - { role: selenoid,  tags: [ 'selenoid'  ] }

Ansible Vault

Using the argument “ — ask-vault-pass”

ansible-playbook users.yml --ask-vault-pass

Using the argument “ — vault-password-file”

ansible-playbook users.yml --vault-password-file /anmol/.ansible/vault-passwd

More about Ansible:

👬 Contribution

  • Open pull request with improvements

  • Discuss ideas in issues

  • Reach out with any feedback Twitter URL

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].