在WEB端通过ansible-playbook+rundeck向服务器推送密钥的简单实现

一、ansible-playbook剧本如下

cat pushssh.yml
---
- hosts: "{{ dsthosts }}"
  user: root
  tasks:
   - name: copysshid
     authorized_key: user=root key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"

 

二、rundeck任务如下

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='dsthosts' values='192.168.156.71' valuesListDelimiter=','>
          <description>执行命令的主机</description>
        </option>
        <option name='ansible_ssh_pass' secure='true' valueExposed='true' />
      </options>
    </context>
    <defaultTab>nodes</defaultTab>
    <description>推送密钥</description>
    <executionEnabled>true</executionEnabled>
    <id>b5d7b564-69b3-43c9-ac3d-0c7befb3a9d6</id>
    <loglevel>INFO</loglevel>
    <name>推送密钥</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <plugins />
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <exec>ansible-playbook /home/ansible/playbooks/pushssh.yml --extra-vars "dsthosts=${option.dsthosts} ansible_ssh_pass=${option.ansible_ssh_pass}" </exec>
      </command>
    </sequence>
    <uuid>b5d7b564-69b3-43c9-ac3d-0c7befb3a9d6</uuid>
  </job>
</joblist>

 

三、执行过程实际调用的后台命令

ansible-playbook pushssh.yml --extra-vars "dsthosts=test ansible_ssh_pass=yourpassword"

ansible_ssh_pass这个参数的名称是固定的,对应了/etc/ansible/hosts文件的vars.ansible_ssh_pass

[test]
10.0.0.1
10.0.0.2
#[test:vars]
#ansible_ssh_pass='yourpassword'

 

 

 

 

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页