I am getting validation error…
Below is my playbook.
hosts: stapp01, stapp02, stapp03
gather_facts: true
become: yes
become_method: sudo
tasks:
- name: create a file using blockinfile
blockinfile:
create: yes
path: /root/facts.txt
block: |
Ansible managed node architecture is <architecture>
- name: Install apache packages
package:
name: httpd
- name: file copy
shell: cp /root/facts.txt /var/www/html/index.html
- name: ensure httpd is running
systemd:
name: httpd
state: restarted
If I understood correct then you need to reed facts about host.
Problem is that you are not reading host architecture with <architecture>
variable ansible_architecture should get right value for you and to write it to file you should use jinja2
Ansible managed node architecture is "{{ ansible_architecture }}"
Also You should add task to question when asking questions.
Good material to read about facts.
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_vars_facts.html
Also You should use ansible copy module to copy file to correct place (your way also is correct, but every time when it’s possible ansible is recomending to use modules.
Example:
- name: ansible copy file locally.
copy:
remote_src: yes
src: /root/facts.txt
dest: /var/www/html/index.html