Giter VIP home page Giter VIP logo

ansible-101's Introduction

Ansible 101

Ansible - is automation.

Install Ansible using your OS related packages.

$ ansible --version
ansible [core 2.11.6]
  config file = None
  configured module search path = ['/Users/haddouti/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/4.7.0/libexec/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/haddouti/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.7 (default, Oct 13 2021, 06:45:31) [Clang 13.0.0 (clang-1300.0.29.3)]
  jinja version = 3.0.2
  libyaml = True

To allow ansible interact with remote host is it mandatory to place the public SSH key (here: bastion_ssh_key) on the remote hosts (here: remote.host.com)

$ ssh-copy-id -i bastion_ssh_key [email protected]

Afterwards test the access via ssh

$ ssh-copy-id -i bastion_ssh_key [email protected]

[user@bastion ~]$

The following sections covers the main capabilities of Ansible with the help of an Ansible role and playbook.

Run a module directly
$ ansible localhost -m ansible.builtin.setup
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.178.26"
        ],
        ...
        "ansible_distribution": "MacOSX",
        "ansible_distribution_major_version": "11",
        ...
    }
Create a role structure
$ ansible-galaxy init playground-role
- Role playground-role was created successfully

tree playground-role
playground-role
├── README.md
├── defaults
│   └── main.yml        # default variables for the role
├── files               # static files used from the role
├── handlers
│   └── main.yml        # handlers, to react on events
├── meta
│   └── main.yml        # meta info and dependencies
├── tasks
│   └── main.yml        # main list of tasks that the role executes
├── templates           # Jinja templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml        # other variables for the role

8 directories, 8 files
Execute Playbook role.yml
$ ansible-playbook -i inventory role.yml
Execute Playbook role.yml to the remote
$ ansible-playbook -i inventory -l remote role.yml -e"ansible_ssh_private_key_file=../../work/internal.bastion_ssh" -e"ansible_python_interpreter=/usr/bin/python3"
Execute Playbook k8s.yml to the remote
$ ansible-playbook -i inventory -l vmhost k8s.yml -e"ansible_ssh_private_key_file=../../work/internal.bastion_ssh" -e"ansible_python_interpreter=/usr/bin/python3"
Install roles and collections as defined in the requirements.yml
$ ansible-galaxy install -r requirements.yml
Install roles and collections as defined in the requirements.yml
$ ansible-galaxy collection install -r requirements.yml -p /path/.ansible/plugins/modules

tbd

This article and project are licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 and the Apache License, Version 2.

See also Apache License FAQ .

ansible-101's People

Contributors

haf-tech avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.