https://github.com/irezaul/ansible
https://github.com/irezaul/ansible
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/irezaul/ansible
- Owner: irezaul
- Created: 2021-07-09T13:24:39.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-08-01T16:47:48.000Z (almost 4 years ago)
- Last Synced: 2025-01-12T21:12:30.293Z (5 months ago)
- Size: 1.43 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `Ansible` How to install on your VM machine ubuntu
#### 1. update first your apt
```python
sudo apt-get update
```
#### 2. `Ansible` use this command for install ( `It only needs to be installed on the master-PC `)
``` phython
sudo apt-get install ansible
```
#### 3. Next need to configure password less SSH: First need to create a `SSH key pair` on AnsibleMaster
```bash
ssh-keygen
```
#### this keyfile generate on `root` folder
```bash
cd root/.ssh
```

> (press enter for all options)
#### 4. To copy the public key type command
```bash
cat .ssh/id_rsa.pub
```
#### 5. and select the key to copy In all the host nodes type command
```bash
vim .ssh/authorized_keys
```
> and paste by right clicking From AnsibleServer ssh to all the nodes once then logout: ssh 19X.16X.1.1### * Configuring Host File
> As root user the host file is under `/etc/ansible/hosts`
> Now you can edit and save the file using vim or nano ( text editor)
`vim /etc/ansible/hosts`
#### 6. Write here your `IP addresses` of the hosts at the bottom of the file in this format and save and exit vim
#### 7. `Ad-hoc` Commands & Modules in Ansible
> Example 1: Use the ping module to check if a host can be pinged
```bash
ansible ip-192.168.x-x -m ping
```

> Example 2: Create a new user by using the user module
```bash
ansible ip-172-31-12-148 -m user -a "name=demouser state=present"
```
#### 8. `Ad-hoc` Commands & Modules in Ansible (cont)
> Check if demouser has been created in host
```bash
id demouser
```
#### 9. Install a package on the host machine using apt module
```bash
ansible ip-172-31-12-148 -m apt -a "name=finger state=present update_cache=true"
```#### 10. Check on the host machine if `finger` was installed by typing finger To run a module on all the hosts use βallβ instead of IP address
```bash
ansible all -m apt -a "name=finger state=present update_cache=true"
```
##### * Create and Execute a Playbook#### 11. Change directory to /etc/ansible:
```bash
cd /etc/ansible
```
#### 12. Use vim editor to write a playbook:
```bash
vim demoplaybook.yaml
```
#### 13. Type this command to execute the play:
```bash
ansible-playbook demoplaybook.yaml
```
### * if you get any `error` like this don't panic just follow the instruction-
> E: Could not get lock /var/lib/dpkg/lock β open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?##### check the process (package manager for handling software). Use this command:
```bash
ps aux | grep -i apt
```
> If you see that apt is being used by a program like `apt.systemd.daily update`,
#### Method 1
```bash
sudo killall apt apt-get
```
#### Method 2
```bash
sudo lsof /var/lib/dpkg/lock
sudo lsof /var/lib/apt/lists/lock
sudo lsof /var/cache/apt/archives/lock
```
#### You can now safely remove the lock files using the commands below:
```bash
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
```
#### [ ] now install your any packages### * Here a demo install java by playbook -
> install process done

[install tomcat apache](https://github.com/irezaul/Ansible/tree/main/Tomcat%20install%20task)