如何在playbook任务中使用ansible_ssh_port

时间:2015-07-30 18:08:24

标签: ansible ansible-playbook

我的情况是我的数据库服务器未使用默认的ssh端口22打开,所以我试图通过端口3838执行查询.Below是代码 -

tasks:
      - name: passive | Get MasterDB IP
        mysql_replication: mode=getslave
        register: slaveInfo

      - name: Active | Get Variable Details
        mysql_variables: variable=hostname ansible_ssh_port=3838
        delegate_to: "{{ slaveInfo.Master_Host }}"
        register: activeDbHostname          

Ansible版本是: - 1.7.2

TASK: [Active | Get Variable Details] *****************************************
<192.168.0.110> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO 192.168.0.110
fatal: [example1.com -> 192.168.0.110] => {'msg': 'FAILED: [Errno 101] Network is unreachable', 'failed': True}

FATAL: all hosts have already failed -- aborting

它通过默认端口22连接而不是连接3838端口。请分享你的想法,如果我在某个地方出错......

1 个答案:

答案 0 :(得分:2)

您应该可以在许多地方指定<tag> <script> if(k){ console.log('cant indent past this'); } </script> </tag> 的值。但您可能希望使用动态库存脚本。

例如。来自$sql = "SELECT * FROM titleList AS ts LEFT JOIN ( SELECT att.filename, GROUP_CONCAT( DISTINCT att.products ) AS myProducts FROM productList AS att GROUP BY att.filename )att ON ts.filename = att.filename LEFT JOIN ( SELECT att2.filename, GROUP_CONCAT( DISTINCT att2.books ) AS myBooks FROM booksList AS att2 GROUP BY att2.filename )att2 ON ts.filename = att2.filename ORDER BY ts.filename"; 档案:

[[UpsertResult  created='true'
 errors='{[1][Error  fields='{[1]Payroll_Type__c,}'
 message='This payroll type is not associated to WSE's account. Please select another.'
 statusCode='FIELD_CUSTOM_VALIDATION_EXCEPTION'
]
,}'
 id='null'
 success='false'
]
]

例如。作为ansible_ssh_port中的变量:

hosts

例如。在动态库存中!您可以使用[db-slave] 10.0.0.20 ansible_ssh_port=3838 的组合并标记实例:

host_vars

使用--- # host_vars/10.0.0.20/default.yml ansible_ssh_port: 3838 group_vars或其他一些动态广告资源脚本,并将您的意见分组到--- # group_vars/db-slaves/default.yml ansible_ssh_port: 3838 文件中:

gce.py

当然,这意味着您需要在启动时标记实例。你可以找到几个dynamic inventory scripts in the ansible repository

如果您的mysqld在同一主机中的docker实例上运行,我建议您使用某种形式的服务发现创建自定义动态库存,例如使用consul,etcd,zookeeper或使用密钥的某些自定义解决方案 - 价值商店,如redis。您可以找到introduction to dynamic inventories in the ansible documentation