我试图在Ubuntu 14.04中使用Ansible剧本设置和配置起搏器。
截至目前,仅在一个节点上对其进行测试。因此,在主机文件中,我只是保留了该节点的信息
[hostname]
1.2.3.4 ansible_ssh_private_key_file=/home/ubuntu/test.pem
在剧本YAML文件中,我尝试安装和配置起搏器
- hosts: all
sudo: yes
tasks:
- name: install pacemaker
apt: name=pacemaker state=present
- name: install corosync
apt: name=corosync state=present
- name: install fence-agents
apt: name=fence-agents state=present
#- copy: src=corosync_start dest=/etc/default/corosync
#- shell: update-rc.d -f pacemaker remove
#- shell: update-rc.d pacemaker start 50 1 2 3 4 5 . stop 01 0 6 .
安装在我的节点中正确进行。但是对于配置,我需要编辑/etc/corosync/corosync.conf,在其中我需要指定我的主机地址来代替bindnetaddress
。
假设我在[主机名]部分下有多个条目-Ansible中有什么方法可以在YAML文件中对其进行循环?
我正在尝试使用sed命令替换IP。您能解释一下如何循环或打印IP吗?
我尝试过这样
- hosts: all
sudo: yes
tasks:
- debug: msg = "{{ ansible_hostname }}"
- name: Test
task: {% for host in groups['app_servers'] %}
{{host}}
{% endfor %}
抱歉让您对我的评论感到困惑,假设您有库存文件
[ALL]
host1.com
host2.com
您的yaml文件应如下所示(使用with_items)
- hosts: all
sudo: yes
tasks:
- name: install pacemaker
apt: name=pacemaker state=present
- name: install corosync
apt: name=corosync state=present
- name: install fence-agents
apt: name=fence-agents state=present
- copy: src=corosync_start dest=/etc/default/corosync
- lineinfile: dest=/etc/selinux/config line="my host {{ item }}"
with_items: groups['ALL']
请记住,它将为每个主机创建每一行,我认为您正在寻找的内容实际上不是循环而是获取当前主机名(ansible_hostname):
- hosts: all
sudo: yes
gather_facts: yes
tasks:
- name: install pacemaker
apt: name=pacemaker state=present
- name: install corosync
apt: name=corosync state=present
- name: install fence-agents
apt: name=fence-agents state=present
- copy: src=corosync_start dest=/etc/default/corosync
- lineinfile: dest=/etc/selinux/config line="my host {{ ansible_hostname }}"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句