LoginSignup
1
5

More than 5 years have passed since last update.

pythonが入っていないホストへansible 実行 (rawモジュール)

Posted at
ansibleからsshのpassword認証用
apt install -y sshpass

サンプル

  • BargeOS にssh鍵を置いてパスワード認証を無効にするサンプル
main.yml
main.yml 
---
- hosts: all
  sudo: yes
  gather_facts: no

  vars:
     authorized_keys: "{{ lookup('file', '../../sshprivate/authorized_keys') }}"

# ------------------------
  tasks:

  - name: .ssh/authorized_keys
    raw: |
      KEY="/home/bargee/.ssh/authorized_keys"
      install -o bargee -g bargees -m 0700 -d /home/bargee/.ssh/
      echo "{{authorized_keys}}" > $KEY
      chown bargee:bargees $KEY
      chmod 600 $KEY

  - name: /etc/ssh/sshd_config
    raw: |
      grep "PasswordAuthentication no" /etc/ssh/sshd_config \
        || (sed -i -e 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config \
            && sshd -t
            && /etc/init.d/S50sshd restart)
hosts
[barge]
b3 ansible_host=192.168.1.2

[all:vars]
ansible_ssh_private_key_file=~/sshprivate/id_rsa
ansible_ssh_user=bargee
ansible_ssh_port=22

注意点

1
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5