Installing Ansible on Ubuntu 18.04 and running simple commands
INSTALL:
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible
CONFIGURE:
*Edit '/etc/ansible/hosts'
*Define 'hosts' - or Ansible clients. Create a group called 'ahosts':
[ahosts]
host1 ansible_ssh_host=192.168.1.28
*Tell Ansible to use python interpreter in path /usr/bin/python3 (shipped with Ubuntu 18.04)
[servers:vars]
ansible_python_interpreter=/usr/bin/python3
*Tell Ansible to use username 'ak' when connecting to hosts (if not using SSH keys):
*Make dir '/etc/ansible/group_vars'
*Edit '/etc/ansible/group_vars/servers'
---
ansible_ssh_user: ak
RUN COMMAND ON HOSTS IN GROUP 'ahosts' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m ping ahosts
RUN COMMAND ON HOSTS 'host1' AND 'host2' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m ping host1:host2
RUN SHELL COMMAND ON HOSTS IN GROUP 'ahosts' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m shell -a 'free -m' ahosts
RUN SHELL COMMAND ON HOSTS IN GROUP 'ahosts' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m shell -a 'touch file.txt' ahosts
sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible
CONFIGURE:
*Edit '/etc/ansible/hosts'
*Define 'hosts' - or Ansible clients. Create a group called 'ahosts':
[ahosts]
host1 ansible_ssh_host=192.168.1.28
*Tell Ansible to use python interpreter in path /usr/bin/python3 (shipped with Ubuntu 18.04)
[servers:vars]
ansible_python_interpreter=/usr/bin/python3
*Tell Ansible to use username 'ak' when connecting to hosts (if not using SSH keys):
*Make dir '/etc/ansible/group_vars'
*Edit '/etc/ansible/group_vars/servers'
---
ansible_ssh_user: ak
RUN COMMAND ON HOSTS IN GROUP 'ahosts' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m ping ahosts
RUN COMMAND ON HOSTS 'host1' AND 'host2' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m ping host1:host2
RUN SHELL COMMAND ON HOSTS IN GROUP 'ahosts' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m shell -a 'free -m' ahosts
RUN SHELL COMMAND ON HOSTS IN GROUP 'ahosts' AND ASK FOR SSH PASSWORD:
ansible --ask-pass -m shell -a 'touch file.txt' ahosts
Kommentarer
Send en kommentar