Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:ansible [2022/07/31 13:54] – [Ansible automation] darrontools:ansible [2024/02/23 11:27] (current) – [Configuration] darron
Line 5: Line 5:
 each managed machine. SSH should to be configured using authorized keys and is not documented here. each managed machine. SSH should to be configured using authorized keys and is not documented here.
  
 +It is recommended to develop the process manually before implementing it in Ansible to allow understanding
 +of any issues that may arise when using Ansible.
 ===Environment=== ===Environment===
  
Line 29: Line 31:
 </code> </code>
  
-No add ~/.local/bin to your $PATH and install pip search+Now add ~/.local/bin to your $PATH and install pip search
 to discover ansible tools. to discover ansible tools.
  
 <code> <code>
-pip3 install pip-search+pip3 install pip-search --break-system-packages
 pip_search ansible pip_search ansible
 </code> </code>
Line 46: Line 48:
  
 <code> <code>
-pip3 install ansible+pip3 install ansible --break-system-packages
 rehash rehash
 +</code>
 +
 +If ansible was already installed and needs updating
 +
 +<code>
 +pip3 install --upgrade ansible --break-system-packages
 </code> </code>
  
Line 190: Line 198:
 Install python3 on each host you wish to perform operations on Install python3 on each host you wish to perform operations on
  
 +__Debian / Kali__
 <code> <code>
 apt install python3 python3-openssl apt install python3 python3-openssl
 +</code>
 +
 +__Red Hat / Oracle __
 +<code>
 +yum install python3 python3-pyOpenSSL
 </code> </code>
  
Line 198: Line 212:
 ===Configuration=== ===Configuration===
  
-Generate default config+Generate default configuration
  
 <code> <code>
 +mkdir -p ~/.ansible
 ansible-config init --disabled -t all > ~/.ansible.cfg ansible-config init --disabled -t all > ~/.ansible.cfg
 </code> </code>
Line 207: Line 222:
  
 <code> <code>
-touch .ansible/hosts +touch ~/.ansible/hosts 
-sed -i 's/;inventory=\/etc\/ansible\/hosts/inventory=~\/.ansible\/hosts/' .ansible.cfg+sed -i 's/;inventory=\/etc\/ansible\/hosts/inventory=~\/.ansible\/hosts/' ~/.ansible.cfg
 </code> </code>
  
Line 233: Line 248:
 supported modules. supported modules.
  
-Here is one to upgrade debian.+Here is one to update debian.
  
-__upgrade.yml__+__debian_update.yml__
 <code> <code>
 --- ---
Line 241: Line 256:
   become: yes   become: yes
   tasks:   tasks:
-  - name: Upgrade+  - name: UPDATE
     ansible.builtin.apt:     ansible.builtin.apt:
       update_cache: yes       update_cache: yes
       upgrade: full       upgrade: full
 +</code>
 +
 +And, another to update REDHAT, Eg. Oracle Linux
 +
 +__redhat_update.yml__
 +
 +<code>
 +---
 +- hosts: VM_REDHAT
 +  become: yes
 +  tasks:
 +  - name: UPDATE
 +    yum:
 +      name: '*'
 +      state: latest
 </code> </code>
  
Line 252: Line 282:
  
 <code> <code>
-ansible-playbook ~/.ansible/upgrade.yml+ansible-playbook ~/.ansible/debian_update.yml
 PLAY [home] *************************************************************************************************************** PLAY [home] ***************************************************************************************************************
  
Line 269: Line 299:
 ok: [PiF] ok: [PiF]
  
-TASK [Upgrade] ************************************************************************************************************+TASK [UPDATE] ************************************************************************************************************
 [WARNING]: Module invocation had junk after the JSON data: 1:23.50s [WARNING]: Module invocation had junk after the JSON data: 1:23.50s
 changed: [PiH] changed: [PiH]
Line 313: Line 343:
 </code> </code>
  
-If you want to see the remote host environments, you can do something like this:+If you want to see the remote host environment, you can do something like this:
  
 <code> <code>
Line 319: Line 349:
 </code> </code>
 ===Resources=== ===Resources===
 +
 +[[https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html|Ansible Inventory]]
  
 [[https://docs.ansible.com/ansible/latest/collections/index_module.html|Ansible Modules]] [[https://docs.ansible.com/ansible/latest/collections/index_module.html|Ansible Modules]]
 +