How to put a script user_data in a CALL API for deploy?

Hi

I manage machines by ansible and API call . I can deploy an ubuntu but once i put user_data on the API CALL; installation failed .

The SH work when i put by GUI … but by call API with same script it failed.

My ansible task :

uri:

     url: "https://uri.com/MAAS/api/2.0/machines/{{id_in_maas}}/?op=deploy"
     method: POST
     body_format: json
     body: "{{ lookup('file','tmp/v3bf33-srv02-deploy.json')  }}"
     headers:
        Authorization: OAuth oauth_consumer_key="*",oauth_token="*",oauth_signature_method="PLAINTEXT",oauth_timestamp="1952448470",oauth_nonce="{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}",oauth_version="1.0",oauth_signature="%26****"
        Content-Type: "application/json"
     use_proxy: yes
     validate_certs: False

FILE v3bf33-srv02-deploy.json

{
“osystem”: “*",
“distro_series”: "
”,
“user_data”: “$(base64 user-data-v3bf33-srv02.sh)”
}

MAAS say : Installation has failed and no output was given. but no log under MAAS UI and the log go too fast under IDRAC console of the server…

File with installation OK :

{
“osystem”: “",
“distro_series”: "

}

I miss something?? someone have an idea??

thanks.

@PouicPouic, I don’t know Ansible, but did you mean to encode or decode user-datav3bf33-srv02.sh in the v3bf33-srv02-deploy.json ? i think the form you have is right, but i’m not sure.

also, you made two changes at once from the non-working file to the working file (“osystem”:"*" vs. “osystem”:"", in addition to excluding the user_data line). maybe get rid of the * in the osystem stanza in the first entry, ie:

{
“osystem”: “*",
“distro_series”: "”,
“user_data”: “$(base64 user-data-v3bf33-srv02.sh)”
}

hi

thanks for the answer . I made a bad copy/past on my original post.
( “osystem”: “*",
“distro_series”: "
”,)

So I dig but don t find a way to make working with ansible URI . … but i success by a CURL ( i am not really happy prefer URI ansible… )

to answer your question, i need to encode the user-data file, used in the deploy step .

in CURL it s working. I put comment: “Test MAX” and see the message in MAAS LOG) , plus instalaltion of Ubuntu ok ans i can connect with spécific process , which is in the user-data file)

- shell: |
     curl -i -X POST -H 'Authorization: {{maas_authent}}' \
      -F user_data="$(base64 -w 0 tmp/user_data_{{hostname}}-deploy.json)" \
      -F osystem='ubuntu' -F distro_series='focal' \
      -F comment='Test max' "https://MAAS-FQDN/MAAS/api/2.0/machines/{{id_in_maas}}/?op=deploy" \
      --cacert ca.pem --output -

but in ANSIBLE MODE I dont find the good way to do the same thing ( I want to cry when I write this )

- name: OS DEPLOY  and user data
 uri:
     url: "https://MAAS-FQDN/MAAS/api/2.0/machines/qcchet/?op=deploy"
     method: POST
     # body_format: json
     body_format: json
     body: 
         osystem: 'ubuntu'
         distro_series: 'focal'
         user_data: '$(base64 user-data-v3bf33-srv02.sh)'
     headers:
        Authorization: OAuth oauth_consumer_key="HIDE",oauth_token="HIDE",oauth_signature_method="PLAINTEXT",oauth_timestamp="1952448470",oauth_nonce="{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}",oauth_version="1.0",oauth_signature="%HIDE"
        Content-Type: "application/json" 
     use_proxy: yes
     remote_src: yes
     validate_certs: False

the file : user-data-v3bf33-srv02.sh
{
“osystem”: “ubuntu/focal”,
“distro_series”: “amd64/ga-20.04”,
“user_data”: “$(base64 ./tmp/user-data-v3bf33-srv02.sh)”
}

By Ansible, the file is never “load” or take in charge by MAAS.

I am upset i do all my " pipeline" with ansible and last step i have a CURL command ^^

I hope to find the problem ( perhaps I am the problem lool )

1 Like

no, i doubt you’re the problem. I wish I had the Ansible experience to help! :slight_smile: