[{"data":1,"prerenderedAt":785},["ShallowReactive",2],{"article-20160607-ansible-composer-install":3},{"article":4,"surround":774},{"id":5,"title":6,"authorKey":7,"body":8,"codeLinks":729,"createdAt":733,"description":734,"excerpt":735,"extension":760,"image":761,"meta":762,"navigation":295,"path":763,"published":764,"readingTime":115,"revisedAt":765,"seo":766,"stem":767,"tags":768,"__hash__":773},"articles\u002Farticles\u002F20160607-ansible-composer-install.md","Install Composer with Ansible, the lean way","philip",{"type":9,"value":10,"toc":727},"minimark",[11,40,58,64,67,78,85,178,188,479,482,510,513,723],[12,13,14,15,22,23,28,29,34,35,39],"p",{},"Every PHP developer needs ",[16,17,21],"a",{"href":18,"rel":19},"https:\u002F\u002Fgetcomposer.org\u002F",[20],"nofollow","Composer"," and as a webhosting company at ",[16,24,27],{"href":25,"rel":26},"https:\u002F\u002Fwww.onlime.ch\u002F",[20],"Onlime GmbH",", sure we had to provide Composer binary to every customer, deploying it to every webserver. But how come the recommended Composer installation for ",[16,30,33],{"href":31,"rel":32},"https:\u002F\u002Fgetcomposer.org\u002Fdoc\u002F00-intro.md#installation-linux-unix-macos",[20],"Linux\u002FUnix\u002FmacOS"," is so clunky, only providing the latest ",[36,37,38],"code",{},"composer.phar"," through an installer?",[12,41,42,43,48,49,51,52,57],{},"Sure, installers are fine, but not for a sysadmin who likes to keep things simple and fully manage his infrastructure with ",[16,44,47],{"href":45,"rel":46},"https:\u002F\u002Fwww.ansible.com\u002F",[20],"Ansible",". Installing Composer should be nothing more than deploying the latest ",[36,50,38],{},", period. But the author of Composer somehow forgot to provide us a download URL for the latest stable version. (Sorry ",[16,53,56],{"href":54,"rel":55},"https:\u002F\u002Fseld.be\u002F",[20],"Jordi Boggiano",", don't want to blame you - maybe I just overlooked it and should have asked you via DM. But writing that small Ansible playbook was still faster than looking any further.)",[12,59,60,61,63],{},"So, I would like to present you a super simple way of grabbing the latest Composer version, download and deploy ",[36,62,38],{},".",[12,65,66],{},"Luckily, the author of Composer provides us with a nice JSON that contains all version information (ok, that's nice!):",[68,69,70],"ul",{},[71,72,73],"li",{},[16,74,77],{"href":75,"rel":76},"https:\u002F\u002Fgetcomposer.org\u002Fversions",[20],"getcomposer.org\u002Fversions",[12,79,80,81,84],{},"We're only interested in ",[36,82,83],{},"stable"," version:",[86,87,92],"pre",{"className":88,"code":89,"language":90,"meta":91,"style":91},"language-json shiki shiki-themes github-light-default github-light-default github-dark-default","{\n  \"stable\": [\n    {\n      \"path\": \"\u002Fdownload\u002F1.1.2\u002Fcomposer.phar\",\n      \"version\": \"1.1.2\",\n      \"min-php\": 50300\n    }\n  ]\n}\n","json","",[36,93,94,103,113,119,135,148,160,166,172],{"__ignoreMap":91},[95,96,99],"span",{"class":97,"line":98},"line",1,[95,100,102],{"class":101},"s_bOF","{\n",[95,104,106,110],{"class":97,"line":105},2,[95,107,109],{"class":108},"sfEsd","  \"stable\"",[95,111,112],{"class":101},": [\n",[95,114,116],{"class":97,"line":115},3,[95,117,118],{"class":101},"    {\n",[95,120,122,125,128,132],{"class":97,"line":121},4,[95,123,124],{"class":108},"      \"path\"",[95,126,127],{"class":101},": ",[95,129,131],{"class":130},"s-BGO","\"\u002Fdownload\u002F1.1.2\u002Fcomposer.phar\"",[95,133,134],{"class":101},",\n",[95,136,138,141,143,146],{"class":97,"line":137},5,[95,139,140],{"class":108},"      \"version\"",[95,142,127],{"class":101},[95,144,145],{"class":130},"\"1.1.2\"",[95,147,134],{"class":101},[95,149,151,154,156],{"class":97,"line":150},6,[95,152,153],{"class":108},"      \"min-php\"",[95,155,127],{"class":101},[95,157,159],{"class":158},"sDkKp","50300\n",[95,161,163],{"class":97,"line":162},7,[95,164,165],{"class":101},"    }\n",[95,167,169],{"class":97,"line":168},8,[95,170,171],{"class":101},"  ]\n",[95,173,175],{"class":97,"line":174},9,[95,176,177],{"class":101},"}\n",[12,179,180,181,184,185,187],{},"So here is my Ansible playbook, that grabs the stable version from ",[16,182,77],{"href":75,"rel":183},[20]," and resolves the download URL from there, then deploys ",[36,186,38],{},":",[86,189,194],{"className":190,"code":191,"filename":192,"language":193,"meta":91,"style":91},"language-yaml shiki shiki-themes github-light-default github-light-default github-dark-default","---\n- hosts: webservers\n  \n  tasks:\n    # Install Composer the lightweight way (without using installer)\n    # https:\u002F\u002Fgetcomposer.org\u002Fdownload\n    - name: Composer | Grab release information\n      uri:\n        url: https:\u002F\u002Fgetcomposer.org\u002Fversions\n        body_format: json\n      register: composer_releases\n\n    - set_fact:\n        composer_version: '{{ composer_releases.json.stable.0.version }}'\n        composer_download_url: 'https:\u002F\u002Fgetcomposer.org{{ composer_releases.json.stable.0.path }}'\n      when: not ansible_check_mode # composer_releases is not registered\n\n    - name: Composer | Install Composer {{ composer_version }}\n      get_url:\n        url: '{{ composer_download_url }}'\n        dest: \u002Fusr\u002Flocal\u002Fbin\u002Fcomposer.phar\n        mode: 0755\n      when: not ansible_check_mode # composer_releases is not registered\n\n    - name: Composer | Symlink composer.phar\n      file:\n        src: composer.phar\n        dest: \u002Fusr\u002Flocal\u002Fbin\u002Fcomposer\n        state: link\n      when: not ansible_check_mode # composer_releases is not registered\n","install-composer.yml","yaml",[36,195,196,201,214,219,227,233,238,251,258,268,279,290,297,307,318,329,343,348,360,368,378,389,400,411,416,428,436,447,457,468],{"__ignoreMap":91},[95,197,198],{"class":97,"line":98},[95,199,200],{"class":158},"---\n",[95,202,203,206,209,211],{"class":97,"line":105},[95,204,205],{"class":101},"- ",[95,207,208],{"class":108},"hosts",[95,210,127],{"class":101},[95,212,213],{"class":130},"webservers\n",[95,215,216],{"class":97,"line":115},[95,217,218],{"class":101},"  \n",[95,220,221,224],{"class":97,"line":121},[95,222,223],{"class":108},"  tasks",[95,225,226],{"class":101},":\n",[95,228,229],{"class":97,"line":137},[95,230,232],{"class":231},"s9BHP","    # Install Composer the lightweight way (without using installer)\n",[95,234,235],{"class":97,"line":150},[95,236,237],{"class":231},"    # https:\u002F\u002Fgetcomposer.org\u002Fdownload\n",[95,239,240,243,246,248],{"class":97,"line":162},[95,241,242],{"class":101},"    - ",[95,244,245],{"class":108},"name",[95,247,127],{"class":101},[95,249,250],{"class":130},"Composer | Grab release information\n",[95,252,253,256],{"class":97,"line":168},[95,254,255],{"class":108},"      uri",[95,257,226],{"class":101},[95,259,260,263,265],{"class":97,"line":174},[95,261,262],{"class":108},"        url",[95,264,127],{"class":101},[95,266,267],{"class":130},"https:\u002F\u002Fgetcomposer.org\u002Fversions\n",[95,269,271,274,276],{"class":97,"line":270},10,[95,272,273],{"class":108},"        body_format",[95,275,127],{"class":101},[95,277,278],{"class":130},"json\n",[95,280,282,285,287],{"class":97,"line":281},11,[95,283,284],{"class":108},"      register",[95,286,127],{"class":101},[95,288,289],{"class":130},"composer_releases\n",[95,291,293],{"class":97,"line":292},12,[95,294,296],{"emptyLinePlaceholder":295},true,"\n",[95,298,300,302,305],{"class":97,"line":299},13,[95,301,242],{"class":101},[95,303,304],{"class":108},"set_fact",[95,306,226],{"class":101},[95,308,310,313,315],{"class":97,"line":309},14,[95,311,312],{"class":108},"        composer_version",[95,314,127],{"class":101},[95,316,317],{"class":130},"'{{ composer_releases.json.stable.0.version }}'\n",[95,319,321,324,326],{"class":97,"line":320},15,[95,322,323],{"class":108},"        composer_download_url",[95,325,127],{"class":101},[95,327,328],{"class":130},"'https:\u002F\u002Fgetcomposer.org{{ composer_releases.json.stable.0.path }}'\n",[95,330,332,335,337,340],{"class":97,"line":331},16,[95,333,334],{"class":108},"      when",[95,336,127],{"class":101},[95,338,339],{"class":130},"not ansible_check_mode",[95,341,342],{"class":231}," # composer_releases is not registered\n",[95,344,346],{"class":97,"line":345},17,[95,347,296],{"emptyLinePlaceholder":295},[95,349,351,353,355,357],{"class":97,"line":350},18,[95,352,242],{"class":101},[95,354,245],{"class":108},[95,356,127],{"class":101},[95,358,359],{"class":130},"Composer | Install Composer {{ composer_version }}\n",[95,361,363,366],{"class":97,"line":362},19,[95,364,365],{"class":108},"      get_url",[95,367,226],{"class":101},[95,369,371,373,375],{"class":97,"line":370},20,[95,372,262],{"class":108},[95,374,127],{"class":101},[95,376,377],{"class":130},"'{{ composer_download_url }}'\n",[95,379,381,384,386],{"class":97,"line":380},21,[95,382,383],{"class":108},"        dest",[95,385,127],{"class":101},[95,387,388],{"class":130},"\u002Fusr\u002Flocal\u002Fbin\u002Fcomposer.phar\n",[95,390,392,395,397],{"class":97,"line":391},22,[95,393,394],{"class":108},"        mode",[95,396,127],{"class":101},[95,398,399],{"class":158},"0755\n",[95,401,403,405,407,409],{"class":97,"line":402},23,[95,404,334],{"class":108},[95,406,127],{"class":101},[95,408,339],{"class":130},[95,410,342],{"class":231},[95,412,414],{"class":97,"line":413},24,[95,415,296],{"emptyLinePlaceholder":295},[95,417,419,421,423,425],{"class":97,"line":418},25,[95,420,242],{"class":101},[95,422,245],{"class":108},[95,424,127],{"class":101},[95,426,427],{"class":130},"Composer | Symlink composer.phar\n",[95,429,431,434],{"class":97,"line":430},26,[95,432,433],{"class":108},"      file",[95,435,226],{"class":101},[95,437,439,442,444],{"class":97,"line":438},27,[95,440,441],{"class":108},"        src",[95,443,127],{"class":101},[95,445,446],{"class":130},"composer.phar\n",[95,448,450,452,454],{"class":97,"line":449},28,[95,451,383],{"class":108},[95,453,127],{"class":101},[95,455,456],{"class":130},"\u002Fusr\u002Flocal\u002Fbin\u002Fcomposer\n",[95,458,460,463,465],{"class":97,"line":459},29,[95,461,462],{"class":108},"        state",[95,464,127],{"class":101},[95,466,467],{"class":130},"link\n",[95,469,471,473,475,477],{"class":97,"line":470},30,[95,472,334],{"class":108},[95,474,127],{"class":101},[95,476,339],{"class":130},[95,478,342],{"class":231},[12,480,481],{},"You could then run this Ansible playbook as follows, limiting it to a single server:",[86,483,487],{"className":484,"code":485,"language":486,"meta":91,"style":91},"language-bash shiki shiki-themes github-light-default github-light-default github-dark-default","$ ansible-playbook install-composer.yml -l myhost -D\n","bash",[36,488,489],{"__ignoreMap":91},[95,490,491,495,498,501,504,507],{"class":97,"line":98},[95,492,494],{"class":493},"sQJ0q","$",[95,496,497],{"class":130}," ansible-playbook",[95,499,500],{"class":130}," install-composer.yml",[95,502,503],{"class":158}," -l",[95,505,506],{"class":130}," myhost",[95,508,509],{"class":158}," -D\n",[12,511,512],{},"done. That was easy.",[514,515,516,522,529,536,545,567,570,720],"blockquote",{},[12,517,518],{},[519,520,521],"strong",{},"UPDATE 2021-08-22:",[12,523,524,525,528],{},"I never looked into this again, as above solution was working perfectly fine for the last years. Also, I am upgrading Composer with a frequent cronjob using ",[36,526,527],{},"composer -q self-update",", which also works flawlessly. But in the meantime, the authors of Composer published this FAQ:",[12,530,531],{},[16,532,535],{"href":533,"rel":534},"https:\u002F\u002Fgetcomposer.org\u002Fdoc\u002Ffaqs\u002Fhow-to-install-composer-programmatically.md",[20],"How do I install Composer programmatically?",[12,537,538,539,544],{},"That solution still looks to clunky in my eyes. But on the ",[16,540,543],{"href":541,"rel":542},"https:\u002F\u002Fgetcomposer.org\u002Fdownload\u002F",[20],"Composer download page",", you'll now finally find a direct link to the latest stable version, including the sha256:",[68,546,547],{},[71,548,549,554,555,560,561,566],{},[16,550,553],{"href":551,"rel":552},"https:\u002F\u002Fgetcomposer.org\u002Fdownload\u002Flatest-stable\u002Fcomposer.phar",[20],"Latest Stable"," (",[16,556,559],{"href":557,"rel":558},"https:\u002F\u002Fgetcomposer.org\u002Fdownload\u002Flatest-stable\u002Fcomposer.phar.sha256",[20],"sha256"," \u002F ",[16,562,565],{"href":563,"rel":564},"https:\u002F\u002Fgetcomposer.org\u002Fdownload\u002Flatest-stable\u002Fcomposer.phar.sha256sum",[20],"sha256sum",")",[12,568,569],{},"So, forget about this whole article (hey, it dates back to 2016!) and replace above Ansible playbook by this simple one:",[86,571,573],{"className":190,"code":572,"filename":192,"language":193,"meta":91,"style":91},"- hosts: webservers\n  \n  vars:\n    composer_url: https:\u002F\u002Fgetcomposer.org\u002Fdownload\u002Flatest-stable\u002Fcomposer.phar\n\n  tasks:\n    # Install Composer the lightweight way (without using installer)\n    # https:\u002F\u002Fgetcomposer.org\u002Fdownload\n    - name: Composer | Install Composer latest-stable\n      get_url:\n        url: '{{ composer_url }}'\n        checksum: 'sha256:{{ composer_url }}.sha256sum'\n        dest: \u002Fusr\u002Flocal\u002Fbin\u002Fcomposer.phar\n        mode: 0755\n\n    - name: Composer | Symlink composer.phar\n      file:\n        src: composer.phar\n        dest: \u002Fusr\u002Flocal\u002Fbin\u002Fcomposer\n        state: link\n",[36,574,575,585,589,596,606,610,616,620,624,635,641,650,660,668,676,680,690,696,704,712],{"__ignoreMap":91},[95,576,577,579,581,583],{"class":97,"line":98},[95,578,205],{"class":101},[95,580,208],{"class":108},[95,582,127],{"class":101},[95,584,213],{"class":130},[95,586,587],{"class":97,"line":105},[95,588,218],{"class":101},[95,590,591,594],{"class":97,"line":115},[95,592,593],{"class":108},"  vars",[95,595,226],{"class":101},[95,597,598,601,603],{"class":97,"line":121},[95,599,600],{"class":108},"    composer_url",[95,602,127],{"class":101},[95,604,605],{"class":130},"https:\u002F\u002Fgetcomposer.org\u002Fdownload\u002Flatest-stable\u002Fcomposer.phar\n",[95,607,608],{"class":97,"line":137},[95,609,296],{"emptyLinePlaceholder":295},[95,611,612,614],{"class":97,"line":150},[95,613,223],{"class":108},[95,615,226],{"class":101},[95,617,618],{"class":97,"line":162},[95,619,232],{"class":231},[95,621,622],{"class":97,"line":168},[95,623,237],{"class":231},[95,625,626,628,630,632],{"class":97,"line":174},[95,627,242],{"class":101},[95,629,245],{"class":108},[95,631,127],{"class":101},[95,633,634],{"class":130},"Composer | Install Composer latest-stable\n",[95,636,637,639],{"class":97,"line":270},[95,638,365],{"class":108},[95,640,226],{"class":101},[95,642,643,645,647],{"class":97,"line":281},[95,644,262],{"class":108},[95,646,127],{"class":101},[95,648,649],{"class":130},"'{{ composer_url }}'\n",[95,651,652,655,657],{"class":97,"line":292},[95,653,654],{"class":108},"        checksum",[95,656,127],{"class":101},[95,658,659],{"class":130},"'sha256:{{ composer_url }}.sha256sum'\n",[95,661,662,664,666],{"class":97,"line":299},[95,663,383],{"class":108},[95,665,127],{"class":101},[95,667,388],{"class":130},[95,669,670,672,674],{"class":97,"line":309},[95,671,394],{"class":108},[95,673,127],{"class":101},[95,675,399],{"class":158},[95,677,678],{"class":97,"line":320},[95,679,296],{"emptyLinePlaceholder":295},[95,681,682,684,686,688],{"class":97,"line":331},[95,683,242],{"class":101},[95,685,245],{"class":108},[95,687,127],{"class":101},[95,689,427],{"class":130},[95,691,692,694],{"class":97,"line":345},[95,693,433],{"class":108},[95,695,226],{"class":101},[95,697,698,700,702],{"class":97,"line":350},[95,699,441],{"class":108},[95,701,127],{"class":101},[95,703,446],{"class":130},[95,705,706,708,710],{"class":97,"line":362},[95,707,383],{"class":108},[95,709,127],{"class":101},[95,711,456],{"class":130},[95,713,714,716,718],{"class":97,"line":370},[95,715,462],{"class":108},[95,717,127],{"class":101},[95,719,467],{"class":130},[12,721,722],{},"I still keep this article online, as it shows how easy it is to parse a JSON with Ansible, even from a remote location.",[724,725,726],"style",{},"html pre.shiki code .s_bOF, html code.shiki .s_bOF{--shiki-light:#1F2328;--shiki-default:#1F2328;--shiki-dark:#E6EDF3}html pre.shiki code .sfEsd, html code.shiki .sfEsd{--shiki-light:#116329;--shiki-default:#116329;--shiki-dark:#7EE787}html pre.shiki code .s-BGO, html code.shiki .s-BGO{--shiki-light:#0A3069;--shiki-default:#0A3069;--shiki-dark:#A5D6FF}html pre.shiki code .sDkKp, html code.shiki .sDkKp{--shiki-light:#0550AE;--shiki-default:#0550AE;--shiki-dark:#79C0FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s9BHP, html code.shiki .s9BHP{--shiki-light:#6E7781;--shiki-default:#6E7781;--shiki-dark:#8B949E}html pre.shiki code .sQJ0q, html code.shiki .sQJ0q{--shiki-light:#953800;--shiki-default:#953800;--shiki-dark:#FFA657}",{"title":91,"searchDepth":105,"depth":115,"links":728},[],[730],{"link":731,"desc":732},"https:\u002F\u002Fgist.github.com\u002Fonlime\u002F8767e4e86d4205e32fbe354c8bea626c","Gist","2016-06-07","Install Composer without running the installer, using an Ansible playbook.",{"type":9,"value":736},[737,750],[12,738,14,739,22,742,28,745,34,748,39],{},[16,740,21],{"href":18,"rel":741},[20],[16,743,27],{"href":25,"rel":744},[20],[16,746,33],{"href":31,"rel":747},[20],[36,749,38],{},[12,751,42,752,48,755,51,757,57],{},[16,753,47],{"href":45,"rel":754},[20],[36,756,38],{},[16,758,56],{"href":54,"rel":759},[20],"md","\u002Fimages\u002Fcovers\u002Fcomposer.jpg",{},"\u002Farticles\u002F20160607-ansible-composer-install",false,null,{"title":6,"description":734},"articles\u002F20160607-ansible-composer-install",[769,770,771,772],"sysadmin","linux","php","ansible","dOFJKBfpatCk8DOQY91ypiEm8Nqma8DqQYHlWq7QLgo",[775,780],{"title":776,"path":777,"stem":778,"createdAt":779,"children":-1},"Setting up PHP & MySQL on OS X Yosemite","\u002Farticles\u002F20141020-osx-yosemite-php-mysql","articles\u002F20141020-osx-yosemite-php-mysql","2014-10-20",{"title":781,"path":782,"stem":783,"createdAt":784,"children":-1},"Proxmox VE 4.x OpenVZ to LXC Migration","\u002Farticles\u002F20160904-proxmoxve4-openvz-to-lxc","articles\u002F20160904-proxmoxve4-openvz-to-lxc","2016-09-04",1794961391538]