Skip to content

Commit

Permalink
Merge pull request #46 from AliMehraji/master
Browse files Browse the repository at this point in the history
Update: README.md And Some Changes in part00
  • Loading branch information
ahmadalibagheri authored Jun 10, 2023
2 parents bc8683d + 284c424 commit f72c5e2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
23 changes: 20 additions & 3 deletions part00-getting-ready/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,28 @@ Systems Ansible

Simple ansible configuration of base systems accorss different environments.

✅ In this example we are going to create a user for DevOps engineers. this dedicated user will have root access to our server.
✅ In this example we are going to create a user for DevOps engineers. this dedicated user will have `root` access to our server.

⚠️ files you need to change before using the code:
- inventory

- `inventory`

### initial step
Try this command to add your users key to the server so you can connect to it using your workstation.

Try this command to add your users key to the server so you can connect to it using your workstation. </br>
For Running below command if `sshpass` package is not installed, you need to install it in your controller node by:

In Feora/Redhat/CentOS
```
yum update -y && yum install -y sshpass
```
In Debian/Ubuntu
```
apt update -y && apt install -y sshpass
```

Then You can invoke below command:

```
ansible all -k -K -m authorized_key -a "user='your_username' state='present' key='{{lookup('file', '~/.ssh/id_rsa.pub')}}'"
```
Expand All @@ -18,6 +34,7 @@ Examples
--------

To run a particular configuration:

```
ansible-playbook ansible-learning.yml
```
Expand Down
12 changes: 6 additions & 6 deletions part00-getting-ready/ansible-learning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
- name: Create account
user:
name: devops
# set bash as default shell for user.
shell: /bin/bash

- name: sudo access
copy:
dest: /etc/sudoers.d/devops
# Granting sudo to created passwordless user
# visudo
content: 'devops ALL=(ALL) NOPASSWD: ALL'
validate: /usr/sbin/visudo -cf %s

- name: set up bash as default shell for user.
user:
name: devops
shell: /bin/bash

- name: ssh key
authorized_key:
user: devops
state: present
manage_dir: yes
key: "{{ lookup( 'file', '~/.ssh/id_rsa.pub') }}"
# Adding ssh_key of a user whi is running playbook.
key: "{{ lookup( 'file', lookup( 'env', 'HOME' ) + '/.ssh/id_rsa.pub') }}"
8 changes: 7 additions & 1 deletion part00-getting-ready/install-python/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
Very First Step
========

Install Python using ansible module `raw` since any other ansible module, such as `apt`, needs python installed:
`ansible-playbook -i hosts.yml -u root python.yml`

```
ansible-playbook -i hosts.yml -u root python.yml
```
20 changes: 11 additions & 9 deletions part00-getting-ready/install-python/script.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash
declare -A osInfo;
osInfo[/etc/debian_version]="apt"
osInfo[/etc/alpine-release]="apk"
osInfo[/etc/centos-release]="yum"
osInfo[/etc/fedora-release]="dnf"

for f in ${!osInfo[@]}
declare -A OS_INFO;
OS_INFO[/etc/debian_version]="apt"
OS_INFO[/etc/alpine-release]="apk"
OS_INFO[/etc/centos-release]="yum"
OS_INFO[/etc/fedora-release]="dnf"

for RELEASE_FILE in ${!OS_INFO[@]}
do
if [[ -f $f ]];then
package_manager=${osInfo[$f]}
if [[ -f $RELEASE_FILE ]];then
PKG_MANAGER=${OS_INFO[$RELEASE_FILE]}
fi
done

$package_manager install python3
$PKG_MANAGER update -y
$PKG_MANAGER install -y python3 python3-pip

0 comments on commit f72c5e2

Please sign in to comment.