---
# System prepended metadata

title: ansible Remote Machine Setting & Controller Machine Setting 002
tags: [Ansible setting]

---

# ansible Remote Machine Setting & Controller Machine Setting 002
:::info
- Linux Ubuntu
:::

## Remote Machine Setting
:::success
被安裝的電腦上需要設定的內容
:::
1. 設置免登密碼登入
```shell=
sudo visudo

會進入 GNU nano 界面, 在將以下設定免密碼在文件底部
[ssh連線名稱(電腦名稱)] 	ALL=(ALL) NOPASSWD:ALL

範例:
root ALL=(ALL) NOPASSWD:ALL
```
2. Install SSH server
```shell=
sudo apt install openssh-server -y
```
## Controller Machine Setting
:::success
啟動安裝的電腦上需要設定的內容
:::

##### Edit /etc/ansible/hosts in controller machine

```
[webservers]
# method 1
<alias> ansible_host=127.0.0.1 ansible_ssh_pass=<your_password> ansible_ssh_user=<your_user_name>

# method 2
<alias> ansible_host=127.0.0.1 
ansible_connection=ssh ansible_ssh_pass=<your_password> ansible_user=<your_user_name>
```

## 使用默認的inventory (/etc/ansible/hosts)

```script=
ansible -i inventory.ini -m ping [group] # 須設定ssh連線

ansible-playbook myplaybook.yml
```
## 指定hosts文件位置

```script=
ansible-playbook -i <hosts file url> myplaybook.yml
```


 ###### tags: `Ansible setting`


