{{ansible_hostname}直接使用ansible 2.3调用时不工作
是否有人在直接调用playbook任务时遇到以下问题 请建议是否有其他方法可以执行此操作,或者如果我在这里做错了什么,我已经用{{ansible_hostname}直接使用ansible 2.3调用时不工作,ansible,ansible-2.x,ansible-facts,Ansible,Ansible 2.x,Ansible Facts,是否有人在直接调用playbook任务时遇到以下问题 请建议是否有其他方法可以执行此操作,或者如果我在这里做错了什么,我已经用lineinfle和替换模块进行了尝试: --- - name: Playbook to Install CollectD hosts: servercast01 gather_facts: False remote_user: root become: true tasks: - name: Replacing hostname entry
lineinfle
和替换模块进行了尝试:
---
- name: Playbook to Install CollectD
hosts: servercast01
gather_facts: False
remote_user: root
become: true
tasks:
- name: Replacing hostname entry
lineinfile:
dest: "/tmp/collectd/etc/collectd.conf"
regexp: '#Hostname "myvm01"'
line: 'Hostname "{{ ansible_hostname }}"'
---
- name: Playbook to Install CollectD
hosts: servercast01
gather_facts: False
remote_user: root
become: true
tasks:
- name: Replacing hostname entry
replace:
dest: /tmp/collectd/etc/collectd.conf
regexp: '#Hostname "myvm01"'
replace: 'Hostname "{{ ansible_hostname }}"'
backup: yes
2) 使用更换模块:
---
- name: Playbook to Install CollectD
hosts: servercast01
gather_facts: False
remote_user: root
become: true
tasks:
- name: Replacing hostname entry
lineinfile:
dest: "/tmp/collectd/etc/collectd.conf"
regexp: '#Hostname "myvm01"'
line: 'Hostname "{{ ansible_hostname }}"'
---
- name: Playbook to Install CollectD
hosts: servercast01
gather_facts: False
remote_user: root
become: true
tasks:
- name: Replacing hostname entry
replace:
dest: /tmp/collectd/etc/collectd.conf
regexp: '#Hostname "myvm01"'
replace: 'Hostname "{{ ansible_hostname }}"'
backup: yes
下面是执行剧本时出现的错误
ansible\u主机名
是一个事实,您已明确禁用收集事实(gather\u facts:False
),因此未定义它
删除该行。ansible\u主机名
是一个事实,您已明确禁用收集事实(收集事实:False
),因此未定义它
拆下管路