Note: ansible base de chez base own test
sudo apt install ansible
ansible --version
sudo mkdir -p /etc/ansible/hosts
cd /etc/ansible/hosts
sudo touch inventory.yml
sudo vi inventory.yml
ansible-inventory -i inventory.yml --list
-------------------------------------------------
TEST
ansible all -i inventory.yml -m command -a "hostname"
OR
ansible all -i inventory.yml -m raw -a "hostname"
----------------------------------------------
mkdir ~/ansible_project
cd ansible_project/
touch hostname_playbook.yml
vi hostname_playbook.yml
cp /etc/ansible/hosts/inventory.yml /home/user/ansible_project/
ansible-playbook -i inventory.yml hostname_playbook.yml
-----------------------------
inventory.yml exemple
```yaml
all:
children:
webservers:
hosts:
xxx.xxx.xxx.xx:
ansible_user: username
ansible_password: password
xxx.xxx.xxx.xx:
ansible_user: username
ansible_password: pissword
```
---------------------------
hostname_playbook.yml exemple
```yaml
---
- name: Get hostname of all servers
hosts: all
tasks:
- name: Run hostname command
command: hostname
register: hostname_output
- name: Display hostname
debug:
msg: "The hostname of {{ inventory_hostname }} is {{ hostname_output.stdout }}"
```
Thu Sep 5 20:20:31 2024 - permalink -
-
http://www.la-pub-dans-les-films.fr/shaarli/?JUFwJA