cancel
Showing results for 
Search instead for 
Did you mean: 
Arpit1309
Cadet
Cadet
  • 329 Views

chapter 3 Lab: Managing Variables and Facts

getiing this error when running playbook.yaml

Arpit1309_0-1750173292780.png

 

can someone plese help with this

4 Replies
Debarshi
Mission Specialist
Mission Specialist
  • 324 Views

You have used a wrong parameter in uri module. You can refer to the link for module details. 

 https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html

and if possible please share the task screenshot so right parameter can be recommended.

Arpit1309
Cadet
Cadet
  • 315 Views

this is the code which is throwing error 

---
- name: install and configure webserver with basic auth
  hosts: webserver
  vars:
    firewall_pkg: firewalld
    firewall_svc: firewalld
    web_pkg: httpd
    web_svc: httpd
    ssl_pkg: mod_ssl
    httpdconf_src: files/httpd.conf
    httpdconf_dest: /etc/httpd/conf/httpd.conf
    htaccess_src: files/.htaccess
    secrets_dir: /etc/httpd/secrets
    secrets_src: files/htpasswd
    secrets_dest: "{{ secrets_dir }}/htpasswd"
    web_root: /var/www/html
  tasks:
    - name: latest version of necessary packages installed
      yum:
        name:
          - "{{ firewall_pkg }}"
          - "{{ web_pkg }}"
          - "{{ ssl_pkg }}"
        state: latest

    - name: configure web service
      copy:
        src: "{{ httpdconf_src }}"
        dest: "{{ httpdconf_dest }}"
        owner: root
        group: root
        mode: 0644

    - name: secrets directory exists
      file:
        path: "{{ secrets_dir }}"
        state: directory
        owner: apache
        group: apache
        mode: 0500

    - name: htpasswd file exists
      copy:
        src: "{{ secrets_src }}"
        dest: "{{ secrets_dest }}"
        owner: apache
        group: apache
        mode: 0400

    - name: .htaccess file installed in docroot
      copy:
        src: "{{ htaccess_src }}"
        dest: "{{ web_root }}/.htaccess"
        owner: apache
        group: apache
        mode: 0400

    - name: create index.html
      copy:
        content: "{{ ansible_facts['fqdn'] }} ({{ ansible_facts['default_ipv4']['address'] }}) has been customized by Ansible.\n"
        dest: "{{ web_root }}/index.html"

    - name: firewall service enable and started
      service:
        name: "{{ firewall_svc }}"
        state: started
        enabled: true

    - name: open the port for the web server
      firewalld:
        service: https
        state: enabled
        immediate: true
        permanent: true

    - name: web service enabled and started
      service:
        name: "{{ web_svc }}"
        state: started
        enabled: true

- name: test web server with basic auth
  hosts: localhost
  become: no
  vars:
    - web_user: guest
  vars_files:
    - vars/secret.yml
  tasks:
    - name: connect to web server with basic auth
      uri:
        url: https://serverb.lab.example.com
        validate_certs: no
        force_basic_auth: yes
        user: "{{ web_user }}"
        password: "{{ web_pass }}"
        return_content: yes
        status_code: 200
      register: auth_test

    - debug:
        var: auth_test.content
Travis
Moderator
Moderator
  • 300 Views

@Arpit1309 - There is no REGISTER option for the URI module which is true. I suspect there is a typo or copy/paste issue with alignment in your classroom lab environment playbook. I would imagine, you did a copy/paste from the book here with the playbook.

If I were to take a bet, I would guess that the REGISTER in your playbook for that URI task at the bottom is indented an additional two (2) spaces and lines up with the status_code. It should be outdented by two spaces as it should align horizontally with the line containing the Ansible module (in this case uri). Again, the playbook above looks OK, but I'm fairly certain, the alignment is your issue on the workstation VM where you are running the playbook. With it being indented, it thinks that REGISTER is a parameter for the module and not actual that you are attempting to register the output of that task.

Travis Michette, RHCA XIII
https://rhtapps.redhat.com/verify?certId=111-134-086
SENIOR TECHNICAL INSTRUCTOR / CERTIFIED INSTRUCTOR AND EXAMINER
Red Hat Certification + Training
Chetan_Tiwary_
Community Manager
Community Manager
  • 281 Views

@Arpit1309 As mentioned by @Travis please adjust your indentation at the below highlighted task and you will be  good :

Chetan_Tiwary__0-1750183922639.pngChetan_Tiwary__1-1750183934883.png

 

0 Kudos
Join the discussion
You must log in to join this conversation.