Skip to content
Snippets Groups Projects
Select Git revision
  • 2c9ee7d8429b8d8a1883dde5d94f197e02d88188
  • master default protected
  • v1.14.7
  • v1.14.6
  • v1.14.5
  • v1.14.4
  • v1.14.3
  • v1.14.2
  • v1.14.1
  • v1.14.0
  • v1.13.2
  • v1.13.1
  • v1.13.0
  • v1.12.1
  • v1.12.0
  • v1.11.1
  • v1.11.0
  • v1.10.0
  • v1.9.2
  • v1.9.1
  • v1.9.0
  • v1.8.4
22 results

test_host_random.yml

Blame
    • Thomas Woerner's avatar
      2c9ee7d8
      test_host_random: No jinja2 templating in conditional statements · 2c9ee7d8
      Thomas Woerner authored
      With ansible-core 2.14.12 using jinja2 templating in conditional
      statements with ansible_facts['fqdn'] is marked as unsafe and results in
      a failure.
      
      The issues with using jinja2 templating in conditional statements for
      asserts have been solved and a new server_fqdn fact has been added for
      ansible_facts['fqdn'].
      2c9ee7d8
      History
      test_host_random: No jinja2 templating in conditional statements
      Thomas Woerner authored
      With ansible-core 2.14.12 using jinja2 templating in conditional
      statements with ansible_facts['fqdn'] is marked as unsafe and results in
      a failure.
      
      The issues with using jinja2 templating in conditional statements for
      asserts have been solved and a new server_fqdn fact has been added for
      ansible_facts['fqdn'].
    test_host_random.yml 3.63 KiB
    ---
    - name: Test ipahost random password generation
      hosts: ipaserver
      become: true
    
      tasks:
      - name: Get Domain from server name
        ansible.builtin.set_fact:
          ipaserver_domain: "{{ ansible_facts['fqdn'].split('.')[1:] | join('.') }}"
        when: ipaserver_domain is not defined
    
      - name: Set host1_fqdn and host2_fqdn
        ansible.builtin.set_fact:
          host1_fqdn: "{{ 'host1.' + ipaserver_domain }}"
          host2_fqdn: "{{ 'host2.' + ipaserver_domain }}"
          server_fqdn: "{{ ansible_facts['fqdn'] }}"
    
      - name: Test hosts absent
        ipahost:
          ipaadmin_password: SomeADMINpassword
          name:
          - "{{ host1_fqdn }}"
          - "{{ host2_fqdn }}"
          update_dns: yes
          state: absent
    
      - name: Host "{{ host1_fqdn }}" present with random password
        ipahost:
          ipaadmin_password: SomeADMINpassword
          name: "{{ host1_fqdn }}"
          random: yes
          force: yes
          update_password: on_create
        register: ipahost
        failed_when: not ipahost.changed or ipahost.failed
    
      - name: Assert ipahost.host.randompassword is defined.
        ansible.builtin.assert:
          that:
          - ipahost.host.randompassword is defined
    
      - name: Print generated random password
        ansible.builtin.debug:
          var: ipahost.host.randompassword
    
      - name: Host "{{ host1_fqdn }}" absent
        ipahost:
          ipaadmin_password: SomeADMINpassword
          name:
          - "{{ host1_fqdn }}"
          state: absent
    
      - name: Host "{{ host1_fqdn }}" is present with random password using hosts parameter
        ipahost:
          ipaadmin_password: SomeADMINpassword
          hosts:
          - name: "{{ host1_fqdn }}"
            random: yes
            force: yes
          update_password: on_create
        register: ipahost
        failed_when: not ipahost.changed or
                     ipahost.host[host1_fqdn].randompassword is not defined or
                     ipahost.failed
    
      - name: Host "{{ host1_fqdn }}" absent
        ipahost:
          ipaadmin_password: SomeADMINpassword
          name:
          - "{{ host1_fqdn }}"