Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
{{ansible_hostname}直接使用ansible 2.3调用时不工作_Ansible_Ansible 2.x_Ansible Facts - Fatal编程技术网

{{ansible_hostname}直接使用ansible 2.3调用时不工作

{{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

是否有人在直接调用playbook任务时遇到以下问题

请建议是否有其他方法可以执行此操作,或者如果我在这里做错了什么,我已经用
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
),因此未定义它

拆下管路